#39721 [NEW]: __autoload and inheritance causes data corruption

From: Date: Sun, 03 Dec 2006 16:52:12 +0000
Subject: #39721 [NEW]: __autoload and inheritance causes data corruption
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-105825@lists.php.net to get a copy of this message
From: dlanoire at neuf dot fr Operating system: Windows XP SP2 PHP version: 5.2.0 PHP Bug Type: Class/Object related Bug description: __autoload and inheritance causes data corruption Description: ------------ __autoload() function causes data corruption when using inheritance. In my example, the value of $foo->instance is 2 and SHOULD BE 1 ! In test.php, if I comment the include_once of autoload.php and uncomment the include_file of classes, the value of $foo->instance is correct (=1). Why ? Normally, there is no difference between autoload and explicit class file inclusion ? Reproduce code: --------------- To test the bug, you need four files. test.php : <?php include_once "autoload.php"; //include_once "test2.php"; //include_once "test2_child.php"; $foo = new test_oop(); $child = new test_oop_child(); echo $foo->instance . "<br>"; echo $child->instance . "<br>"; ?> test2.php : <?php class test_oop { private static $instances = 0; public $instance; public function __construct() { $this->instance = ++self::$instances; } } // class ?> test2_child.php : <?php include_once "autoload.php"; class test_oop_child extends test_oop { } // class ?> autoload.php : <?php function __autoload($className) { require_once $className . ".php"; } ?> Expected result: ---------------- $foo->instance = 1 Actual result: -------------- $foo->instance = 2 -- Edit bug report at http://bugs.php.net/?id=39721&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39721&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39721&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39721&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39721&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39721&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39721&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39721&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39721&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39721&r=support Expected behavior: http://bugs.php.net/fix.php?id=39721&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39721&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39721&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39721&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39721&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39721&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39721&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39721&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39721&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39721&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39721&r=mysqlcfg

« previous php.bugs (#105825) next »