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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tuft at centrum dot cz
New email:
PHP Version: OS:

 

 [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: Fri Apr 26 09:01:29 2024 UTC