Re: Collections / Static typing - was "array or list of objects of different types"

From: Date: Sun, 04 Apr 2010 01:29:25 +0000
Subject: Re: Collections / Static typing - was "array or list of objects of different types"
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-303804@lists.php.net to get a copy of this message
On 04/03/10 23:00, Nathan Rixham wrote:
Peter Pei wrote:
var_dump( array( true , 12 , "php already does this" ) ); array(3) {
    [0]=>   bool(true)
    [1]=>   int(12)
    [2]=>   string(21) "php already does this"
} :)
Yeah. But this feature of PHP is a boon if used carefully and a curse if careless. You can get AMAZING results if you're not careful to check the data types ;)
And that's why language like C# and java supports<> to restrict the type of data a collection can hold.
As a side point; I replicated a load of type safe collections etc for PHP (a good chunk of the java collections stuff) - If it's of use to anybody I can stick them in a google code project or suchlike. They'll obviously never be as fast as Java/C but they do allow for static typing of collections using primitive types or Classes. regards, Nathan
We don't want to decrease the performance, do we ? Best is to use the is_* functions :P -- Nilesh Govindarajan Site & Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु !

« previous php.general (#303804) next »