php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11768 references still have bugs
Submitted: 2001-06-28 03:29 UTC Modified: 2001-11-17 13:34 UTC
From: zork at pablosoft dot com dot pl Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.0 Latest CVS (2001-06-28) OS: Linux 2.2.x
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
6 - 4 = ?
Subscribe to this entry?

 
 [2001-06-28 03:29 UTC] zork at pablosoft dot com dot pl
When I want to set reference to $this object gets copied.
In this example $ui_handler contains copy of object $test.
$ui_handler -> data is not reference to $test.
I use CVS 2001-06-24.

<?
class CUI_element {
	var $value;
	function CUI_element($value) {
		global $ui_handler;
		$this -> value = $value;
		$ui_handler -> register($this);		
	}
}

class CUI_handler {
	var $data;
	
	function CUI_handler() {
		$this -> data = false;
	}
	
	function register(&$element) {
		$this -> data = &$element;
	}
};

$ui_handler = new CUI_Handler();
$test = new CUI_Element("test");
$test -> value = "changed";
var_dump($ui_handler -> data); print "<br>";
var_dump($test); print "<br>";
?>

My output:
object(cui_element)(1) { ["value"]=> string(4) "test" } 
object(cui_element)(1) { ["value"]=> string(7) "changed" } 

Working url: http://biuro.pablosoft.com.pl/~zork/ref/tests.php

regards,
Zork.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-17 13:34 UTC] mfischer@php.net
The line

  $test = new CUI_Element("test");

didn't return $this but a copy of $this. So change it to

  $test = &new CUI_Element("test");

and it works.

Closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC