[PHP] include/include_once php_check_syntax() / E_PARSE errors

2005-11-15 Thread Thiago Silva
Hello all,
Recently I had some problems with include/include_once.

This is the scenario:

My application uses only classes loaded through a centered __autoload()
function (no require/include anywere in the scripts, but in __autoload()
itself).

Now, diverse libraries use diverse extensions. For instance, Smarty class is
declared in Smarty.class.php. And many of my classes uses a simple .php
extension.

So, __autload has to *try* include_once's. Something like that:

function __autoload($className) {
 include_once(${className}.php);
 if(class_exists($className, false)) return;

 include_once(${className}.class.php);
 if(class_exists($className, false)) return;

 die(class not found: $className);
}

Then, loading Smarty would generate a warning message because the first
include_once tries to load Smarty.php (wich doesn't exists). 

Since those warning messages are common, naturaly I use @include_once
statements. 

But, as soon as I'm writing scripts, and one of the classes included
generates an E_PARSE error, I get a blank result in my browser, because @
supress the messages. 

Having explained the problem, I would like to know:

1: Is there an elegant way to resolve this?

2: What happened to php_check_syntax?

3: What was the final word about include() behavior regarding E_PARSE error?
Reading and searching the bug database, I read some posts that seemed to
indicate that include() should *not* halt on E_PARSE errors, but then, php5
does halt the execution. 

4: Halting the execution on E_PARSE error generated through an include() is
a coherent/expected behavior? (it doesn't seem to me). 

5: Why? (depending on the answer to that question, I'll head to
bugs.php.net).

Thanks,
Thiago

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] include/include_once php_check_syntax() / E_PARSE errors

2005-11-15 Thread Curt Zirzow
On Tue, Nov 15, 2005 at 10:48:56PM +, Thiago Silva wrote:
 ...
 So, __autload has to *try* include_once's. Something like that:
 
 function __autoload($className) {
  include_once(${className}.php);
  if(class_exists($className, false)) return;
 
  include_once(${className}.class.php);
  if(class_exists($className, false)) return;
 
  die(class not found: $className);
 }
 
 Then, loading Smarty would generate a warning message because the first
 include_once tries to load Smarty.php (wich doesn't exists). 

 ...
 Having explained the problem, I would like to know:
 
 1: Is there an elegant way to resolve this?

For third party classes I usually extend it myself with my own
naming convention, so like with smarty I would create a class like:

Template.php:
?php
require_once('path/where/smartyis.php');

class Template extends Smarty {
}

 
 2: What happened to php_check_syntax?

It was removed for technical reasons. one option is to use:
  http://php.net/runkit

 3: What was the final word about include() behavior regarding E_PARSE error?
 Reading and searching the bug database, I read some posts that seemed to
 indicate that include() should *not* halt on E_PARSE errors, but then, php5
 does halt the execution. 
 
 4: Halting the execution on E_PARSE error generated through an include() is
 a coherent/expected behavior? (it doesn't seem to me). 
 
 5: Why? (depending on the answer to that question, I'll head to
 bugs.php.net).

This does seem odd.
  http://bugs.php.net/bug.php?id=31736

It seems it was fixed then, although 5.1 seems to be broke for me.
5.0 is fine.


Curt.
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php