On Fri, 2007-07-13 at 02:15 -0500, 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. :-)
>
>
> #2
> array (1) {
> 'foo' => 'foo'
> }
>
> Which might work just fine for whatever the original code was doing,
> but isn't quite the same as what happens...
>
> #3
> array (1) {
> 'foo' => TRUE
> }
>
> Bit of a stretch, I suppose...
>
> #4
> ERROR: Invalid typecast of String to Array.
>
> Not very PHP, I suppose, but there it is...
Waves hands wildly and dismissively in the air. *pshaw*
:)
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