|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-12-29 13:41 UTC] jani@php.net
[2009-12-29 14:52 UTC] grzegorz at heex dot pl
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 14:00:02 2025 UTC |
Description: ------------ That code works: class A{ private $data; public function __construct() { $this->data = new stdClass(); } public function & __get($property) { if (isset($this->data->$property)) { return $this->data->$property; } return null; } public function __set($property,$value) { $this->data->$property = $value; } } function chgTxt(& $txt) { $txt = '-----'; } $o = new A(); $o->int = 1; $o->int++; echo $o->int,'<br />';//result: 2 - reference in A::get() works fine $o->txt = 'string'; chgTxt($o->txt); echo $o->txt,'<br />';//result: '----' - reference works Reproduce code: --------------- That code doesn't work: class A{ private $data; public function __construct() { $this->data = new stdClass(); } public function & __get($property) { return isset($this->data->$property) ? $this->data->$property : null; } public function __set($property,$value) { $this->data->$property = $value; } } function chgTxt(& $txt) { $txt = '-----'; } $o = new A(); $o->int = 1; $o->int++; echo $o->int,'<br />';//result: 2 - reference in A::get() works fine $o->txt = 'string'; chgTxt($o->txt); echo $o->txt,'<br />';//result: 'string' - reference doesn't work Expected result: ---------------- 2 ---- Actual result: -------------- 2 string