fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

Extending Core and php syntax errors... #657

Closed ronan-gloo closed 12 years ago

ronan-gloo commented 12 years ago

While extending a core class, if the new class has syntax error, the framework autoload seem's to refuse to load the new class, but it still registered in global \ namespace, and report a "Fatal error: Class 'SomeClass' not found..."

an example with Uri class

class Uri extends Fuel\Core\Uri { $some $stupid $error = "Fatal error: Class 'Uri' not found"; }

In this case, i've tried to remove the "\", prefix from Uri::string() in Core/finder.php at 310. The class is instantiate and error reported.

jschreuder commented 12 years ago

I tested this and as expected I just get the syntax error, wouldn't be any other error as PHP will always end up in a shutdown error on any syntax error encountered and couldn't continue to end up in the "Class 'Someclass' not found". If the file with the syntax error is loaded into the PHP parser it'll stop exeuction in its tracks way before the autoloader can fail.

Thus as far as I can see the system can't find the file or doesn't parse it.

ronan-gloo commented 12 years ago

The logger seem's to catch and write the syntax error. I'll try to reproduce this on an other server.

WanWizard commented 12 years ago

@ronan-gloo: any progress on this?

ronan-gloo commented 12 years ago

Stille same results on Os X env. with php 5.3.8 (previous was Centos and php5.3.3).

Errors log from apache is reportings both:

PHP Parse error: syntax error, unexpected ';' in (...)/fuel/app/classes/uri.php on line 27 PHP Fatal error: Class 'Uri' not found in (...)/fuel/core/classes/finder.php on line 310

(Tested on "fresh" install of fuelphp)

It seem's that the syntax error is not fatal in this case. Uri class is registered even after the parse error. So fuel "think" that the class is available, and finally crash.

WanWizard commented 12 years ago

This gives me (in the browser):

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in APPPATH/classes/uri.php on line 4 Fatal error: Class 'Uri' not found in COREPATH/classes/finder.php on line 309

The issue in this particular case is that the syntax error triggered FuelPHP's error handling, which needs the Uri class to display the error. So you're in a catch-22 situation. And because the autoloader aborts when the error occurs, it can't alias the core class to the global namespace (which would ignore this error).

If you do the same with a non-critical class (for example View), you will see the standard FuelPHP error message.

So basically, there's nothing that can be done about this.