Re: Bug 28879: Populating arrays with resources and objects as offsets

From: Date: Thu, 24 Jun 2004 01:33:54 +0000
Subject: Re: Bug 28879: Populating arrays with resources and objects as offsets
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-10740@lists.php.net to get a copy of this message
> But since there's no BC need to allow resources in array initialization, > then sure, leave it to the scripter to cast it to an int if that's REALLY > what they want. (Again "why?" comes to mind). PEAR::DB uses this method - I'm seeing a million errors on sites that have updated to latest CVS version. You're forced to i use this method if you want to link a resource back to it's creation information. If you have an array of IPs, and you create an array of resources from each IP, a third array linking the IP back to the casted interger value of the resource is required if you want to get the IP back. (This is very confusing to write). Here's an example: <?php $servers[] = "139.134.253.11:27025"; $servers[] = "203.114.130.7:27015"; foreach ($servers as $server) { list($ip, $port) = explode(':', $server); $sock = @fsockopen("udp://" . $ip, $port, $errno, $errstr, 1); if ($sock !== false) { $sockets[] = $sock; // Create an array so we can link the socket back to the server $server_keys[$sock] = array_search($server, $servers); } } while (stream_select($r, $w = null, $e = null, 0, calctimeout($maxtime, $starttime)) !== 0) { ++$i; foreach ($r as $socket) { $response = stream_get_contents($socket); // Put the response into an array with the original IP as the key $results[$server_keys[$socket]][] = $response; } } ?> I hope that demonstrates the purpose properly. Ofcourse this method can still be used, it just requires an extra cast (which is a cleaner solution anyway). Regards, Aidan

« previous php.internals (#10740) next »