#39337 [NEW]: Array creation when using overloading (__get) does not work (NULL)
| From: | phpbugs at thequod dot de | Date: | Wed, 01 Nov 2006 18:41:14 +0000 |
| Subject: | #39337 [NEW]: Array creation when using overloading (__get) does not work (NULL) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-104263@lists.php.net to get a copy of this message | ||
From: phpbugs at thequod dot de
Operating system: Ubuntu Linux
PHP version: 5CVS-2006-11-01 (CVS)
PHP Bug Type: Arrays related
Bug description: Array creation when using overloading (__get) does not work (NULL)
Description:
------------
Creating an array through $obj->a[] or $obj->a[$index]
does not create an array, if you use overloading through
the "__get()" method.
This happens with PHP_5_2 and 5.1.6 from Ubuntu, which
I've also tested.
The workaround seems to be to initialize the member
explicitly to "array()".
Reproduce code:
---------------
<?php
class A
{
function __get($v)
{
// note: even returning array() here won't fix it
}
}
$A = new A();
$A->foo[1] = 1;
var_dump( $A->foo );
$A->foo[] = 2;
var_dump( $A->foo );
$A->foo['a'] = 3;
var_dump( $A->foo );
$A->foo = array();
var_dump( $A->foo );
$A->foo = 1;
var_dump( $A->foo );
?>
Expected result:
----------------
array(1) {
[1]=>
int(1)
}
array(2) {
[1]=>
int(1)
[2]=>
int(2)
}
array(3) {
[1]=>
int(1)
[2]=>
int(2)
["a"]=>
int(3)
}
array(0) {
}
int(1)
Actual result:
--------------
NULL
NULL
NULL
array(0) {
}
int(1)
--
Edit bug report at http://bugs.php.net/?id=39337&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39337&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39337&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39337&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39337&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=39337&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39337&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39337&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39337&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39337&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39337&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=39337&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=39337&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39337&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39337&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39337&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39337&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39337&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39337&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39337&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39337&r=mysqlcfg