php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #47291 get and set are not fixed
Submitted: 2009-02-03 16:20 UTC Modified: 2009-11-20 10:12 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: ies_clan at hotmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.2.8 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ies_clan at hotmail dot com
New email:
PHP Version: OS:

 

 [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
                        )

                )

        )

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-10 07:25 UTC] 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-11-20 10:12 UTC] vrana@php.net
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.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 16:02:26 2025 UTC