#47291 [Opn->Bgs]: get and set are not fixed
ID: 47291
Updated by: vrana@php.net
Reported By: ies_clan at hotmail dot com
-Status: Open
+Status: Bogus
Bug Type: Documentation problem
Operating System: Windows XP
PHP Version: 5.2.8
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2009-09-10 07:25:33] torben@php.net
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.
------------------------------------------------------------------------
[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
Thread (2 messages)