|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-02-03 16:20 UTC] 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 ) ) ) ) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 11:00:01 2025 UTC |
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.