Re: 'odd' handling of $moo['bar'] where $moo is a string
| From: | Evan Priestley | Date: | Thu, 09 Feb 2006 22:06:08 +0000 |
| Subject: | Re: 'odd' handling of $moo['bar'] where $moo is a string | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-21831@lists.php.net to get a copy of this message | ||
When indexing a string, the string is cast to an integer:
(int)'file' == 0
When in a conditional expression, the string is cast to a boolean:
(bool)'file' == true
It isn't necessarily a fatal error, consider:
$keys[ '3' ]
- Evan
On Feb 9, 2006, at 4:54 PM, Ian P. Christian wrote:
Can someone explain the following to me? echo "DEBUG:\n"; var_dump($keys); var_dump($keys['file']); var_dump(isset($keys['NOTEXISTING'])); var_dump(isset($keys['file'])); exit; DEBUG: string(19) "myConsoleController" string(1) "m" bool(true) bool(true) Now, it seems that $keys['file'] == $keys[0], which makes sense why the issets return true. However... if ('file') echo 'true'; will print moo, therefore 'file' == 1, not 0. Why is this different when using it as a string offset? IMO, using a string as a string offset, a fatal error should be raised. Kind Regards, --Ian P. Christian http://pookey.co.uk --PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php