Edit report at https://bugs.php.net/bug.php?id=49657edit=1
ID: 49657
Comment by: phillip dot berndt at googlemail dot com
Reported by:pvenakis at efrontlearning dot net
Summary:array_search returns null instead of false
Status: Not a bug
Type: Bug
Package:Unknown/Other Function
Operating System: windows
PHP Version:5.3.0
Block user comment: N
Private report: N
New Comment:
I disagree. This function returning NULL is nothing I'd expect. Especically
since this behavior still (it's 2012!) is not documented. This IS a bug. If not
because of the feature, at least one regarding missing documentation.
In PHP 4.2, you changed this function such that it returns FALSE in case of an
error, which, as was pointed out above by the other commenter, is good, because
it makes existence checking easy. Since FALSE !== NULL, things get pretty
complicated now.
Previous Comments:
[2011-11-26 16:11:57] rodrigovb at gmail dot com
I'd like to advise you about the impact of this change in the company I work.
Based on the last return value (FALSE) we had 40 php files with some lines
checking the result of array_search (=== false). This is a small company with
30 employees (and 40 php files to be changed).
The concern of the owner is if PHP is sustainable enough to keep investing in
develop instead of maintenance due to this changes.
Please write the change log (or point the link with the log) cointaining the
real needs of this ghange.
In my point of view the impact of return value changes of any function could be
severe, specially in bigger companies.
[2009-09-25 07:14:46] pvenakis at efrontlearning dot net
Thanks for the quick response. It's fine that it returns null, but since this
changed from 5.2 to 5.3 it would be nice if it were mentioned in the changelog
or in the documents.
Best Regards, Periklis
[2009-09-24 12:17:22] paj...@php.net
That's expected. Returning NULL on invalid argument(s) is correct.
[2009-09-24 12:03:47] pvenakis at efrontlearning dot net
Description:
array_search returns false in 5.2.x, null in 5.3.0, when $haystack is not an
array
Reproduce code:
---
$haystack = false; //Anything not an array
$result = array_search(1, $haystack);
var_dump($result);
Expected result:
bool(false)
Actual result:
--
null
--
Edit this bug report at https://bugs.php.net/bug.php?id=49657edit=1