ID:               39721
 Updated by:       [EMAIL PROTECTED]
 Reported By:      dlanoire at neuf dot fr
-Status:           Assigned
+Status:           Closed
 Bug Type:         Class/Object related
 Operating System: Windows XP SP2
 PHP Version:      5.2.0
 Assigned To:      dmitry
 New Comment:

Fixed in CVS HEAD and PHP_5_2.


Previous Comments:
------------------------------------------------------------------------

[2006-12-04 17:28:36] dlanoire at neuf dot fr

fix summary

------------------------------------------------------------------------

[2006-12-04 17:04:44] dlanoire at neuf dot fr

To give you more inputs, if I replace the echo functions by var_dump, I
notice that $foo->instance IS A REFERENCE, as you can see in my printout
:

object(test2)#1 (1) {
  ["instance"]=>
  &int(2)
}
object(test2_child)#2 (1) {
  ["instance"]=>
  int(2)
}

Furthermore, if I replace "$child = new test2_child()" by "$child = new
test2()", there is no bug with __autoload so I suppose thet the problem
comes from inheritance ...
Hope that helps.

------------------------------------------------------------------------

[2006-12-03 17:04:26] dlanoire at neuf dot fr

Sorry, I made a mistake with the source code. The good one is :

test.php :
<?php
include_once "autoload.php"; 
//include_once "test2.php";
//include_once "test2_child.php";

$foo = new test2();
$child = new test2_child();
echo $foo->instance . "<br>";
echo $child->instance . "<br>";
?>

test2.php :
<?php
class test2 {
        private static $instances = 0;
        public $instance;
        
        public function __construct() {
                $this->instance = ++self::$instances;
        }
         
} // class
?>

test2_child.php :
<?php
include_once "autoload.php"; 

class test2_child extends test2 {
         
} // class
?>

autoload.php :
<?php
function __autoload($className) {
        require_once $className . ".php";
} 
?>

------------------------------------------------------------------------

[2006-12-03 16:52:12] dlanoire at neuf dot fr

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 this bug report at http://bugs.php.net/?id=39721&edit=1

Reply via email to