ID: 47291
Updated by: torben@php.net
Reported By: ies_clan at hotmail dot com
Status: Open
Bug Type: Documentation problem
Operating System: Windows XP
PHP Version: 5.2.8
New Comment:
You need to declare Options as an element in the $vars property before
writing to its elements. You could either do this by declaring $vars as
protected $vars = array('Options' => array());
or by doing this:
$Pet = new Pet();
$Pet->Options = array();
$Pet->Name = 'I am a pet';
I'm not sure this is a doc bug. Seems like you should definitely be
getting notices but that they should be 'undefined offset' or 'undefined
variable' notices instead of what is actually issued.
Previous Comments:
------------------------------------------------------------------------
[2009-02-03 16:20:59] ies_clan at hotmail dot com
Description:
------------
get and set are not fixed: http://bugs.php.net/bug.php?id=39449
Reproduce code:
---------------
<?php
error_reporting(E_ALL | E_STRICT);
abstract class Property {
protected $vars = array();
public function &__get($Key)
{
if(array_key_exists($Key, $this->vars)){
return $this->vars[$Key];
}
}
public function __set($Key, $Value)
{
$this->vars[$Key] = $Value;
}
}
class Human extends Property {}
class Pet extends Property {}
$Pet = new Pet();
$Pet->Name = 'I am a pet';
$Human = new Human();
$Human->Mypet = $Pet;
$Human->Mypet->Options['HumanID'] = 1;
print_r($Human);
?>
Expected result:
----------------
Human Object
(
[vars:protected] => Array
(
[Mypet] => Pet Object
(
[vars:protected] => Array
(
[Name] => I am a pet
)
)
)
)
Actual result:
--------------
Notice: Only variable references should be returned by reference in
D:\apache\htdocs\phpbug\index.php on line 15
Notice: Indirect modification of overloaded property Pet::$Options has
no effect in D:\apache\htdocs\phpbug\index.php on line 31
Human Object
(
[vars:protected] => Array
(
[Mypet] => Pet Object
(
[vars:protected] => Array
(
[Name] => I am a pet
)
)
)
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47291&edit=1