On 08/06/2010 04:44 PM, Richard Quadling wrote:
On 6 August 2010 15:33, mathieu.suen<mathieu.s...@easyflirt.com>  wrote:
Hi,

For now you can only index an array using a scalar type or a string.
Is there some rfc or work going on to enlarge the possibility so that it is
possible to have some other object like:

- closure
- object
- etc.

Thanks

-- Mathieu Suen
If an object implements a __toString() magic method, then it can work ...


<?php
class randomizer {
        public function __toString() {
                return (string)mt_rand();
        }
}

$randomizer = new randomizer;
$array = array (
        "$randomizer" =>  'First',
        "$randomizer" =>  'Second',
        "$randomizer" =>  'Third',
        "$randomizer" =>  'Fourth',
);

print_r($array);
?>

outputs ...

Array
(
     [1365443950] =>  First
     [1235256771] =>  Second
     [520059180] =>  Third
     [486985268] =>  Fourth
)

Well that is not the expected behavior since if you call array_keys you won't get the object.

--Mathieu Suen


        

Reply via email to