|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7515 very weird, magic, invisible referencing
Submitted: 2000-10-28 10:25 UTC Modified: 2002-06-03 09:33 UTC
Avg. Score:3.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Latest CVS (28/10/2000) OS: linux + win2k
Private report: No CVE-ID: None
 [2000-10-28 10:25 UTC]
This code is pretty self-explanatory...

Uncommenting the noticed (*[0]) line, causes the object contained ('root') in the instance of 'obj'  to be referenced to whatever, function test() uses a copy $o_copy but reference-counting fails and the contained object 'root' is somehow referenced to the original object in the global scope.
After having uncommented *[0] try to uncomment *[1] what should break the reference again, that made me assuming this all is caused by reference counting...

class obj {
	function method() {}

function test($o_copy) {
	//$o_copy->root=&$o_copy->root; // *[1]

 	var_dump($o_copy);?><BR><?php }

$o->root=new obj();
//$o->root->method();	// *[0] uncomment this line and weirdness starts



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-16 13:40 UTC]
assigned to zeev, as discussed we either need
a) a permanent fix
b) a permanent deep copy function and understand this effect
as a feature and users will eventually have to use deep
copies for some containers
 [2001-12-12 08:14 UTC]
Is this still a issue? This report is updated a year ago...
If this report is outstanding, PHP Version is better to be updated...
 [2002-01-11 16:11 UTC] bryce at redhat dot com
I'm looking at putting php 4.1.1 into the next RH release 
however I noticed that this bug still seems to be happening 

(From make test)
Running tests in /usr/src/redhat/php-4.1.1//tests/lang
OO Bug Test (Bug #7515) (029.phpt)          ... failed

[root@dhcpd201 lang]# cat  029.exp
[root@dhcpd201 lang]# cat  029.out

I this something that can either be fixed or can I turn a
blind eye to this..

 [2002-04-11 15:28 UTC]
I have reproducted this problem... and am pretty sure what is exactly is going wrong...
class foo
 function foo()
  $this->bar = new bar();

class bar
 function bar()
  $this->tmp = "bar";
 function do_nothing()
$foo = new foo();
$foo->bar->tmp = "test";
$foo2 = $foo;
$foo2->bar->tmp = "foo";

// now....
$foo3 = $foo;
$foo3->bar->tmp = "bug";

 Basically when you call a method from a objects member object. It creates that member as a refrence. 

/* i set this to critical because i think this should be resloved right away */

- Brad

 [2002-06-03 09:33 UTC]
Zend Engine 2 fixes this.
 [2011-11-22 22:44 UTC] yann-gael at gueheneuc dot net
I compiled PHP 4.2.3 for m68k-amigaos and the test case tests/lang/029.php fails. Could you tell me more about what has been changed into the Zend engine to fix this bug so that I can track this change and the bug?

(I don't think that I should reopen this bug for m68k-amigaos, should I?)

 [2011-11-22 23:31 UTC] yann-gael at gueheneuc dot net
PS. I narrowed down the test:
    class obj {
            function method() {
    $o->root=new obj();


and its output with PHP 4.2.3 compiled for m68k-amigaos:
    object(stdClass)(1) {
      object(obj)(0) {
    object(stdClass)(1) {
      &object(obj)(0) {

(note the ampersand in the second dump), while, with PHP 5.2.14 for Windows, the output is:
    object(stdClass)#2 (1) {
      object(obj)#1 (0) {
    object(stdClass)#2 (1) {
      object(obj)#1 (0) {

Does it make sense that in the second assign "$o->root->method();", the method is viewed as a reference to and object?

Please forgive me if my question is silly, I am a newbie in OO PHP.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 19:01:25 2019 UTC