note 68303 added to function.isset
| From: | php-general at lists dot php dot net | Date: | Fri, 21 Jul 2006 14:08:56 +0000 |
| Subject: | note 68303 added to function.isset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115014@lists.php.net to get a copy of this message | ||
I tried the example posted previously by Slawek:
$foo = 'a little string';
echo isset($foo)?'yes ':'no ', isset($foo['aaaa'])?'yes
':'no ';
He got yes yes, but he didn't say what version of PHP he was using.
I tried this on PHP 5.0.5 and got: yes no
But on PHP 4.3.5 I got: yes yes
Apparently, PHP4 converts the the string 'aaaa' to zero and then returns the string
character at that position within the string $foo, when $foo is not an array. That means you
can't assume you are dealing with an array, even if you used an expression such as
isset($foo['aaaa']['bbb']['cc']['d']), because it will
return true also if any part is a string.
PHP5 does not do this. If $foo is a string, the index must actually be numeric (e.g. $foo[0]) for it
to return the indexed character.
----
Server IP: 216.194.113.175
Probable Submitter: 65.213.231.9
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.isset.php
Edit -- http://master.php.net/note/edit/68303
Del: integrated -- http://master.php.net/note/delete/68303/integrated
Del: useless -- http://master.php.net/note/delete/68303/useless
Del: bad code -- http://master.php.net/note/delete/68303/bad+code
Del: spam -- http://master.php.net/note/delete/68303/spam
Del: non-english -- http://master.php.net/note/delete/68303/non-english
Del: in docs -- http://master.php.net/note/delete/68303/in+docs
Del: other reasons-- http://master.php.net/note/delete/68303
Reject -- http://master.php.net/note/reject/68303
Search -- http://master.php.net/manage/user-notes.php