php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50355 Trying to access a magical property by reference only raises an E_NOTICE.
Submitted: 2009-12-01 19:20 UTC Modified: 2009-12-01 19:36 UTC
From: oorza2k5 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.1 OS: *
Private report: No CVE-ID: None
 [2009-12-01 19:20 UTC] oorza2k5 at gmail dot com
Description:
------------
When trying to access a magically returned (via __get()) property of a class, only an E_NOTICE is raised.  

While a function like array_pop will return a value (without modifying the overloaded property), some other operations will have less predictable results, such as array access via the "[]" syntax.  Because a lot of distributions ship with a "$something | ~E_NOTICE" level of error reporting, and the "black box" ideas of object oriented programming (a developer trying to push an element onto a member array in an API class, for instance), this could be a very hard circumstance to debug.  Furthermore, any case I can think of where this notice will be raised will never perform as expected, it will force the developer to re-engineer his solution.  Because any case where this error would be raised will force a rewrite, I think that this circumstance should raise a fatal error instead.

The fix is trivial enough that I did not attach a patch, but would be glad to in the future, if necessary.

Reproduce code:
---------------
<?php

class foo {
        private $bar = array('1', '2', '3');
        public function __get($var) {
                return $this->$var;
        }
}

$inst = new foo();
var_dump(array_pop($inst->bar));


Expected result:
----------------
PHP Fatal Error:  Indirect modification of overloaded property foo::$bar has no effect in /home/blahblah/test.php on line 10


Actual result:
--------------
PHP Notice:  Indirect modification of overloaded property foo::$bar has no effect in /home/blahblah/test.php on line 10


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-01 19:36 UTC] jani@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 20:01:32 2025 UTC