Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10021 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3437 invoked by uid 1010); 22 May 2004 06:40:29 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 3400 invoked by uid 1007); 22 May 2004 06:40:29 -0000 Message-ID: <20040522064028.3397.qmail@pb1.pair.com> To: internals@lists.php.net Date: Sat, 22 May 2004 16:40:36 +1000 Lines: 40 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-Posted-By: 144.132.76.67 Subject: Internal casting of objects as array keys From: aidan@php.net ("Aidan Lister") Hello devs, I'd like to discuss the use of objects as array keys. _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 "
";
var_dump($array);
echo "
"; ?> 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