|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-04-07 16:02 UTC] kilbyc at bellsouth dot net
Description: ------------ http://us1.php.net/in_array is at best misleading, at worst, blatantly wrong. The documentation clearly states that in_array returns bool, true, false. Null is not an acceptable value in that list. Also, the manual does not advise that this function may throw warnings. This has been ignored for a while. https://bugs.php.net/bug.php?id=39788 Test script: --------------- C:\php5.5>php --version PHP 5.5.11 (cli) (built: Apr 2 2014 16:03:05) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies C:\php5.5>php -r "var_export(in_array('thing', null));" Warning: in_array() expects parameter 2 to be array, null given in Command line NULL Expected result: ---------------- Update the manual to say that in_array issues Warning. And: Either returns NULL if the array is null. OR Fix the function to return false is the array is null. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 17 07:00:01 2025 UTC |
It gets worse What about the people who read the manual and see the bool sig, and therefore implement something like: $is_authorized = in_array('user',$roles)!==false;//and $roles failed to init The developer doesn't know there is a potential warning there, or to look for a null.