Re: Re: Internal casting of objects as array keys

From: Date: Tue, 25 May 2004 13:12:56 +0000
Subject: Re: Re: Internal casting of objects as array keys
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-10088@lists.php.net to get a copy of this message
This code doesn't seem to have changed. Can you send me a 3-4 liner which errors out in PHP 4 and not in PHP 4? Thanks, Andi At 11:03 PM 5/25/2004 +1000, Aidan Lister wrote:
I'm going to go ahead and post this as a bug, unless there is a reason noone replied... "Aidan Lister" <aidan@php.net> wrote in message news:20040522064028.3397.qmail@pb1.pair.com... Hello devs, I'd like to discuss the use of objects as array keys. <?php class idobject {
    private $_id;
    function __construct ($id) { $this->_id = $id; }
    function __tostring () {  return (int)$this->_id; }
} $blah1 = new idobject(1); $blah2 = new idobject(2); $blah3 = new idobject(3); $blah4 = new idobject(4); $array = array ( $blah1 => 'blah1', $blah2 => 'blah2', $blah3 => 'blah3', $blah4 => 'blah4', ); echo "<pre>"; var_dump($array); echo "</pre>"; ?> In PHP4 this results in an error, In PHP5 there is no error, the array is simply empty. An array key can only be a string/int, thus, when someone attempts to use an array as a key would it not make sense to cast the object? This behaviour would then be consistant with resources. Regards, Aidan -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.internals (#10088) next »