array or list of objects of different types

array or list of objects of different types

am 03.04.2010 01:52:57 von PHP Developer

--0-994987062-1270252377=:82868
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi all, I want to be able to have an array of elements of different ty=
pes. As an example: the first element is a boolean, the second is an intege=
r, and the thirs is a string. In php there is no typing, i'm just wond=
ering if there is a way to have that, it would be a lot better than having =
an array of strings and have to convert each element. Thank you =
____________________________________________________________ ___=
___=0AThe new Internet Explorer=AE 8 - Faster, safer, easier. Optimized fo=
r Yahoo! Get it Now for Free! at http://downloads.yahoo.com/ca/internetexp=
lorer/
--0-994987062-1270252377=:82868--

Re: array or list of objects of different types

am 03.04.2010 02:12:48 von Nathan Rixham

Php Developer wrote:
> Hi all,
>
> I want to be able to have an array of elements of different types. As an example: the first element is a boolean, the second is an integer, and the thirs is a string.
>
> In php there is no typing, i'm just wondering if there is a way to have that, it would be a lot better than having an array of strings and have to convert each element.
>

var_dump( array( true , 12 , "php already does this" ) );

array(3) {
[0]=> bool(true)
[1]=> int(12)
[2]=> string(21) "php already does this"
}

:)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: array or list of objects of different types

am 03.04.2010 04:12:54 von Nilesh Govindrajan

On 04/03/10 05:42, Nathan Rixham wrote:
> Php Developer wrote:
>> Hi all,
>>
>> I want to be able to have an array of elements of different types. As an example: the first element is a boolean, the second is an integer, and the thirs is a string.
>>
>> In php there is no typing, i'm just wondering if there is a way to have that, it would be a lot better than having an array of strings and have to convert each element.
>>
>
> 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 ;)

--
Nilesh Govindarajan
Site & Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: array or list of objects of different types

am 03.04.2010 16:57:36 von Peter Pei

>>
>> 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.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Collections / Static typing - was "array or list of objects of differenttypes"

am 03.04.2010 19:30:36 von Nathan Rixham

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

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

am 03.04.2010 20:14:23 von Peter Pei

On Sat, 03 Apr 2010 11:30:36 -0600, Nathan Rixham
wrote:

> 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

That will be wonderful.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

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

am 04.04.2010 03:29:25 von Nilesh Govindrajan

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
मेरा भारत महान !
मम भारत: महत्तम भवतु !

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php