From:             oorza2k5 at gmail dot com
Operating system: Irrelevant
PHP version:      5.3.1
PHP Bug Type:     *General Issues
Bug description:  Trying to access a magical property by reference only raises 
an E_NOTICE.

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


-- 
Edit bug report at http://bugs.php.net/?id=50355&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50355&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50355&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50355&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50355&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50355&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50355&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50355&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50355&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50355&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50355&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50355&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50355&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50355&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50355&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50355&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50355&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50355&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50355&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50355&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50355&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50355&r=mysqlcfg

Reply via email to