array or list of objects of different types

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

Hi all,=0A=0AI 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.=0A=0AIn 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.=0A=0AThank you=0A=0A=
=0A=0A ____________________________________________________________ ___=
___=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--
PHP Developer [ Sa, 03 April 2010 01:52 ] [ ID #2037634 ]

Re: array or list of objects of different types

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
Nathan Rixham [ Sa, 03 April 2010 02:12 ] [ ID #2037635 ]

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

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
Nilesh Govindrajan [ Sa, 03 April 2010 04:12 ] [ ID #2037637 ]

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

>>
>> 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
Peter Pei [ Sa, 03 April 2010 16:57 ] [ ID #2037657 ]

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

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
Nathan Rixham [ Sa, 03 April 2010 19:30 ] [ ID #2037674 ]

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

On Sat, 03 Apr 2010 11:30:36 -0600, Nathan Rixham <nrixham [at] gmail.com>
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
Peter Pei [ Sa, 03 April 2010 20:14 ] [ ID #2037675 ]

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

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
Nilesh Govindrajan [ So, 04 April 2010 03:29 ] [ ID #2037730 ]
PHP » gmane.comp.php.general » array or list of objects of different types

Vorheriges Thema: Just a test.
Nächstes Thema: GetElementByClass?