note 118045 added to function.in-array
| From: | dazero0 dot ls at gmail dot com | Date: | Thu, 24 Sep 2015 10:43:33 +0000 |
| Subject: | note 118045 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203844@lists.php.net to get a copy of this message | ||
I would like to add something to beingmrkenny at gmail dot com comparison post. After debugging a
system, i discovered a security issue in our system and his post helped me find the problem.
In my additional testing i found out that not matter what you search for in an array, except for 0
and null, you get true as the result if the array contains true as the value.
Examples as php code :
<?php
$a = ['a', 32, true, 'x' => y];
var_dump(in_array(25, $a)); // true, one would expect false
var_dump(in_array('ggg', $a)); // true, one would expect false
var_dump(in_array(0, $a)); // false
var_dump(in_array(null, $a)); // false
?>
Such the best practice in our case is to use strict mode. Which was not so obvious.
----
Server IP: 194.50.97.16
Probable Submitter: 217.87.123.137
----
Manual Page -- http://php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/118045
Del: integrated -- https://master.php.net/note/delete/118045/integrated
Del: useless -- https://master.php.net/note/delete/118045/useless
Del: bad code -- https://master.php.net/note/delete/118045/bad+code
Del: spam -- https://master.php.net/note/delete/118045/spam
Del: non-english -- https://master.php.net/note/delete/118045/non-english
Del: in docs -- https://master.php.net/note/delete/118045/in+docs
Del: other reasons-- https://master.php.net/note/delete/118045
Reject -- https://master.php.net/note/reject/118045
Search -- https://master.php.net/manage/user-notes.php