#50606 [Bgs]: strange behavior of reference and ? operator
| From: | grzegorz at heex dot pl | Date: | Tue, 29 Dec 2009 14:52:25 +0000 |
| Subject: | #50606 [Bgs]: strange behavior of reference and ? operator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-146188@lists.php.net to get a copy of this message | ||
ID: 50606
User updated by: grzegorz at heex dot pl
Reported By: grzegorz at heex dot pl
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Win XP
PHP Version: 5.3.1
New Comment:
The first code (IF...ELSE) works and there is no Notice.
Is there a bug in ? operator.
Previous Comments:
------------------------------------------------------------------------
[2009-12-29 13:41:24] jani@php.net
You should try with error_reporting = E_ALL once:
Notice: Only variable references should be returned by reference...
Notice: Indirect modification of overloaded property..
------------------------------------------------------------------------
[2009-12-29 13:02:28] grzegorz at heex dot pl
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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50606&edit=1