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] [email protected]

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

Reply via email to