0

I inherited some PHP source code, and I have to maintain it. It has been built from scratch using no framework, just the former developer's own creation.

Now, I ask this:

Is there a way to ignore fatal errors in php.ini/ini_settings only without modifying the code?

Scenario:

SomeClass.php:

<?php class SomeClass {
...)?>

index.php:

include("SomeClass.php");
...
include("SomeClass.php");

In my development box, this throws a Fatal Error exception (because SomeClass has been declared twice), which is the obvious and expected behavior.

Here is the kicker: This source is hosted somewhere, and it works. I just don't ANY access to that server.

So I see here two scenarios:

1.) There is a way to silence this Fatal Error via 2 includes by an ini setting. This I have to know.

2.) The former developer did NOT give me the exact, updated source code that is currently up and running. I then have to insist that he give me the latest source code, but I can only do this if I am 100% sure that there is no way #1 can happen.

What do you guys think?

2
  • Honestly, that sounds like a nightmare scenario where much of your task depends on something you have no control over. I'd either get my hands on that source or start looking elsewhere. Commented Apr 28, 2011 at 5:35
  • What can I say? Life. ;) Commented Apr 28, 2011 at 5:39

4 Answers 4

2

I tried setting a set_error_handler() function that doesn't die on fatal errors, but instead Apache crashed. In other words, PHP needs to die so that the system doesn't.

So, sorry, I really don't think there is a solution for that.

Sign up to request clarification or add additional context in comments.

Comments

1

Fatal errors don't come from the include function - only warnings. You'd get fatals from require, though. Use @include and it won't even generate the warning.

4 Comments

Thanks for the answer, but then I have to modify the source code, which then means that I did not receive the latest code from the former developer. What I'm really looking for is if there is a way (or not) to silence this using ini settings ONLY
Ah, I misinterpreted your post. You can set the error reporting level in php.ini - google "php error_reporting php.ini", but there's nothing you can do about FATAL errors flying out of this app. They can't (and should not) be suppressed.
that's what I'm thinking as well, but then again maybe I missed an ini setting that can suppress this Fatal Error...
Nope, you can't suppress them. Nothing will do it.
0

Error reporting is mostly discouraged on production servers. Why let the user see if your script didn't find a file. Have a look at this http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors and http://www.php.net/manual/en/function.set-error-handler.php. The latter could be helpful, go through the page for examples. I suggest to log errors instead of displaying it. But that will involve some sort of workaround with code.

Comments

0

inform your developer that he should use __autoload or spl_autoload to avoid such errors…

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.