php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39788 in_array don't return false or true
Submitted: 2006-12-10 13:26 UTC Modified: 2014-04-07 17:00 UTC
From: roberto at spadim dot com dot br Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.0 OS: ALL
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: roberto at spadim dot com dot br
New email:
PHP Version: OS:

Further comment on this bug is unnecessary.

 

 [2006-12-10 13:26 UTC] roberto at spadim dot com dot br
Description:
------------
RETURN NULL?!?! see documentation

http://br.php.net/manual/pt_BR/function.in-array.php

just can return TRUE or FALSE! NULL isn't allowed!
see that i'm using 4 parameters and no error was showed

Reproduce code:
---------------
<?php

	$images=array(
		"cabec0" => "cabec0",		"cabec1" => "cabec1",
		"cabec2" => "cabec2",		"cabec3" => "cabec3",
		"cabec4" => "cabec4",
		"login0" => "login0",		"login1" => "login1",
		"login2" => "login2",		"login3" => "login3",
		"login4" => "login4",

		"messenger0" => "messenger0",	"messenger1" => "messenger1",
		"messenger2" => "messenger2",	"messenger3" => "messenger3",
		"messenger4" => "messenger4",

		"file_explorer0" => "explorer0","file_explorer1" => "explorer1",
		"file_explorer2" => "explorer2","file_explorer3" => "explorer3",
		"file_explorer4" => "explorer4",
		
		"yellow"=>"yellow","red"=>"red",
		"gray"=>"gray","blue"=>"blue","green"=>"green",

		"logo"   => "logo.png",		"smm"   => "smm.gif"
	);

$image='rodape';
var_dump(in_array($image,'logo','rodape','smm'));
print_r($images);
?>

Expected result:
----------------
FALSE

Actual result:
--------------
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-10 14:09 UTC] tony2001@php.net
PHP Warning:  Wrong parameter count for in_array() in /tmp/6.php on line 25

Warning: Wrong parameter count for in_array() in /tmp/6.php on line 25
NULL

 [2014-04-07 15:47 UTC] kilbyc at bellsouth dot net
I am not entirely sure how this can be filed as "Not a Bug"
Regardless of the emission of the Warning, the documentation clearly states that in_array returns bool, true, false. Null is not an acceptable value in that list.

One of the two things needs to be fixed. Either update the manual to say that in_array throws a Warning, and returns NULL if the array is null.

OR

Fix the function to return false is the array is null.
 [2014-04-07 17:00 UTC] requinix@php.net
-Block user comment: No +Block user comment: Yes
 [2014-04-07 17:00 UTC] requinix@php.net
Thanks for bringing this ticket back up again after almost 7.5 years.

It is well established that internal functions may return NULL when you pass invalid or not enough arguments. It's stated on the manual page for internal functions. Making that note again on every single function's documentation page is redundant.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 03:01:29 2024 UTC