#34109 [NEW]: __autoload interupting normal "code flow"
| From: | info at tphnet dot com | Date: | Fri, 12 Aug 2005 20:01:23 +0000 |
| Subject: | #34109 [NEW]: __autoload interupting normal "code flow" | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-83476@lists.php.net to get a copy of this message | ||
From: info at tphnet dot com
Operating system: Windows XP SP2
PHP version: 5.0.4
PHP Bug Type: Class/Object related
Bug description: __autoload interupting normal "code flow"
Description:
------------
I've been toying around a bit with the __autoload() functionallity and
along the way found some strange behaviour.
I'm not entirely sure it's bug, but it's at least not working as I would
expect it.
I created a system which allows classes to register themselfs with a
"registration object" when loaded. When registering, some checks are
executed to (for example) see if the class that's being registered is of
the right type.
Below is a very simplified version of my script, it serves no purpose but
to show my problem.
Reproduce code:
---------------
Index.php
<?php
function __autoload($class){
include($class . '.php');}
$Class = new Class2();
?>
Class1.php
<?php
class Class1{
public static function CheckClass2(){
is_subclass_of('Class2', 'Class1');}}
?>
Class2.php
<?php
Class1::CheckClass2();
class Class2 extends Class1{}
?>
Expected result:
----------------
When running Index.php, a blank page should be displayed.
Actual result:
--------------
When running Index.php, the following error appears:
Warning: Unknown class passed as parameter in Class1.php on line 7
I can only assume that by using the __autload() function the normal flow
of code processing is changed in some way.
Class2 seems not to be defined by the time the CheckClass2() method is
called, even though Class2.php should've been included before Class1.php
(where this method is located).
When I manually include both files in Index.php the code works fine, same
goes for placing the call to CheckClass2() below the definition of
Class2.
Again, I'm not sure whether this is a bug or just "the way it works". It's
although not what I would expect to happen...
--
Edit bug report at http://bugs.php.net/?id=34109&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34109&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34109&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34109&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=34109&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=34109&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=34109&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=34109&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=34109&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34109&r=support
Expected behavior: http://bugs.php.net/fix.php?id=34109&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=34109&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=34109&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=34109&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34109&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=34109&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=34109&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34109&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=34109&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=34109&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=34109&r=mysqlcfg