Ask a Question related to PHP Bugs, Design and Development.
-
phpbugs at thequod dot de #1
#39337 [Opn]: Array creation when using overloading (__get) does not work (NULL)
ID: 39337
User updated by: phpbugs at thequod dot de
Reported By: phpbugs at thequod dot de
Status: Open
Bug Type: Arrays related
Operating System: Ubuntu Linux
PHP Version: 5CVS-2006-11-01 (CVS)
New Comment:
A better workaround is, of course, to just define the
member with "var" in the class header.
But it's still a bug IMHO.
Previous Comments:
------------------------------------------------------------------------
[2006-11-01 18:41:14] phpbugs at thequod dot de
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 this bug report at [url]http://bugs.php.net/?id=39337&edit=1[/url]
phpbugs at thequod dot de Guest
-
#40797 [NEW]: empty() breaks when overloading with __get
From: stephan_schmidt at usa dot com Operating system: Windows 200X PHP version: 5.2.1 PHP Bug Type: Class/Object related... -
#39337 [NEW]: Array creation when using overloading (__get) does not work (NULL)
From: phpbugs at thequod dot de Operating system: Ubuntu Linux PHP version: 5CVS-2006-11-01 (CVS) PHP Bug Type: Arrays... -
#24608 [Ver]: __set not triggered when overloading with array
ID: 24608 Updated by: andrew@php.net Reported By: jaanus at heeringson dot com Status: Verified Bug Type: ... -
#24608 [Opn->Ver]: __set not triggered when overloading with array
ID: 24608 Updated by: sniper@php.net Reported By: jaanus at heeringson dot com -Status: Open +Status: ... -
#24608 [Com]: __set not triggered when overloading with array
ID: 24608 Comment by: itotakas at msu dot edu Reported By: jaanus at heeringson dot com Status: Open Bug Type:...



Reply With Quote

