php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34241 unexpected references behavior
Submitted: 2005-08-24 21:57 UTC Modified: 2005-08-30 14:21 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: tuft at centrum dot cz Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.4 OS: windows xp
Private report: No CVE-ID: None
 [2005-08-24 21:57 UTC] tuft at centrum dot cz
Description:
------------
when I call "$variable = $this" inside the class it will create only reference, it won't create new instance of object(it behave exactly like "$variable = &$this" should behave) and "$variable = &$this" don't do anything.

Reproduce code:
---------------
class A
{
	var $t = "Original <br>";
	
	function A()
	{
		global $active;
		$active = $this;   
	}
	
	function test(){echo $this->t;}
} 

function f()
{
	  global $active; 
	  $active->t = "Changed <br>";
	  $active->test();
}

$a = new A();
$a->test();
f();
$a->test();	

Expected result:
----------------
Original
Changed
Original

Actual result:
--------------
Original
Changed
Changed

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-24 22:09 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is PHP 5\'s new OO model for you.
 [2005-08-30 14:21 UTC] tuft at centrum dot cz
I read throw the documentation and I haven't found any notice about this strange behavior. The documentation says that $this is reference to the instance of object (even in new php5 00 model), documentation also says that reference is not pointer when you create reference to variable both variables are equal, they point to the same place. But in our situation $this behave like pointer. So I think there is a mistake somewhere, in the documentation or in the php5 OO model.
It would be nice if at least $var = &$this worked in php5 for compatibility. IMHO the whole new OO model should be compatible with the old one, but it do not belong here(my dream / future request).
Thanks for your time and for developing such nice scripting language.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 14:01:31 2024 UTC