Edit report at http://bugs.php.net/bug.php?id=52251&edit=1

 ID:               52251
 Comment by:       giorgio dot liscio at email dot it
 Reported by:      giorgio dot liscio at email dot it
 Summary:          in __set() $obj->{222} = $foo; 222 is casted to string
 Status:           Open
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: all?
 PHP Version:      5.3.2

 New Comment:

arrayaccess interface has a different behavior and allows to pass
instances as keys



anyway there's another issue about "classic" arrays



$myarray[new MyClass()] = "foo";



when used in this context, the instance should call __toString to return
the key as string... or toScalar in the next php releases


Previous Comments:
------------------------------------------------------------------------
[2010-07-05 14:35:24] giorgio dot liscio at email dot it

Description:
------------
hi



class MyArray

{

   public function __set($i,$v){var_dump($i);}

   public function __get($i){var_dump($i);}

}



$obj = new MyArray();

$obj->{222} = "foo";

echo $obj->{222};



i think the index of the __set __get magic methods should be as user
passed

with the characteristics of a "php's valid array key"

















but in plus...

would be nice if the key accepts all types too



$hashtable->{new User(2222)} = new SomeUserData(2222);



here User is casted to "string" and it is good for hash tables, but
inside the __set method is impossible to access the original "new User"
instance



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



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52251&edit=1

Reply via email to