Doc #67038 [Com]: in_array returns null

From: Date: Mon, 07 Apr 2014 16:20:22 +0000
Subject: Doc #67038 [Com]: in_array returns null
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-11121@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67038&edit=1 ID: 67038 Comment by: kilbyc at bellsouth dot net Reported by: kilbyc at bellsouth dot net Summary: in_array returns null Status: Open Type: Documentation Problem Package: Documentation problem Operating System: Windows 7 PHP Version: 5.5.11 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2014-04-07 16:02:21] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67038&edit=1

« previous php.doc.bugs (#11121) next »