Re: Array Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2007-07-14 at 00:55 -0500, Richard Lynch wrote:
> On Fri, July 13, 2007 2:15 am, Richard Lynch wrote:
> > On Thu, July 12, 2007 8:29 am, Robert Cummings wrote:
> >> Hmmm, I thought using an explicit cast was very self explanatory --
> >> especially when the name of the cast is "array". Maybe I'm alone in
> >> that
> >> thought. I mean if you convert a scalar to an array what do you
> >> expect
> >> to get? An array with the scalar. *shrug* I can't see how it would
> >> be
> >> anything else.
> >
> > $foo = (array) 'foo';
> > var_dump($foo);
> >
> > A couple perfectly reasonable (though wrong) outputs:
> >
> > #1
> > array (3){
> >   0 => 'f',
> >   1 => 'o',
> >   2 => 'o'
> > );
> >
> > And, actually, PHP having been derived (partially) from C, one could
> > almost argue this is the EXPECTED output. :-)
> 
> In retrospect, given that $foo[1] is 'o' and that you can treat $foo
> JUST like an array of characters, the EXPECTED output from a C->PHP
> perspective might be:
> 
> string (3) 'foo'
> 
> It already *IS* an array, to a large extent.
> 
> :-)

When in Rome do as the Romans. PHP has a very distinct definition for an
array and for a string. If you think you're using C then maybe you
should go read the documentation. Assumptions based on previous
experience only go as far as they are right. Since you explicitly cast
to an array and not to a string, it can only be expected that you have
an array -- or an exception as you previously offered. But we know you
get an array because it's documented.

:)

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux