ID:               39337
 User updated by:  phpbugs at thequod dot de
 Reported By:      phpbugs at thequod dot de
-Status:           Bogus
+Status:           Open
 Bug Type:         Arrays related
 Operating System: Ubuntu Linux
 PHP Version:      5CVS-2006-11-01 (CVS)
 New Comment:

Ok. But haven't you seen the comment in __get()?

Here's another testcase, just returning an array now 
always and with further output, when __get() gets called:


Description:
------------
When using "array creating syntax" (like $a[] or $a[1]), 
__get() does not seem to work correctly, IF the var has 
not been defined using the "var" key for the class.

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:
----------------
__get: foo
array(1) {
  1 => 1
}
array(2) {
  1 => 1,
  2 => 2
}
array(0) {
  1 => 1,
  2 => 2,
  'a' => 3
}
array(0) {
}
int(1)


Actual result:
--------------
__get: foo
__get: foo
array(0) {
}
__get: foo
__get: foo
array(0) {
}
__get: foo
__get: foo
array(0) {
}
array(0) {
}
int(1)


Previous Comments:
------------------------------------------------------------------------

[2006-11-08 17:40:51] [EMAIL PROTECTED]

It's not in the manual, because it's obvious - your __get() method does
nothing, so you get nothing as the result.

------------------------------------------------------------------------

[2006-11-08 17:30:53] phpbugs at thequod dot de

Sorry, it's not in the manual..

http://de.php.net/manual/en/language.oop5.overloading.php

Please re-classify as "documentation issue" at least, if you're sure
that it really is not a bug..

------------------------------------------------------------------------

[2006-11-08 14:10:52] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php



------------------------------------------------------------------------

[2006-11-01 18:56:44] phpbugs at thequod dot de

A better workaround is, of course, to just define the 
member with "var" in the class header.

But it's still a bug IMHO.

------------------------------------------------------------------------

[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 http://bugs.php.net/?id=39337&edit=1

Reply via email to