php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51520 strict-parameter of array_search() and object-identity
Submitted: 2010-04-09 15:53 UTC Modified: 2010-04-09 16:04 UTC
From: r dot wilczek at web-appz dot de Assigned: degeberg (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.2 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: r dot wilczek at web-appz dot de
New email:
PHP Version: OS:

 

 [2010-04-09 15:53 UTC] r dot wilczek at web-appz dot de
Description:
------------
Documentation for array_search() says: "If the third parameter strict is set to TRUE  then the array_search() function will also check the types of the needle in the haystack."

But: if the array contains objects, setting the strict-parameter to TRUE will check for object-identity, not only for equality of type and value.

If the comparison would check for equality of type and value only,
the strict variant would output int(0) in the example below, for $foo and $bar do not differ in type or value.

I suggest to supplement the documentation.

Test script:
---------------
$foo = new stdClass; $foo->foo = 'a';
$bar = clone $foo;

var_dump(array_search($bar, array($foo)));     
var_dump(array_search($bar, array($foo), true));

Expected result:
----------------
If the documentation is right (and array_search() has a bug):
int(0)
int(0)

If the documentation is wrong (and array_search() currently works as expected):
int(0)
bool(false)

Actual result:
--------------
int(0)
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-09 16:04 UTC] degeberg@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&revision=297745
Log: Fixed PHP bug #51520 (strict-parameter of array_search() and object-identity)
 [2010-04-09 16:04 UTC] degeberg@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: degeberg
 [2010-04-09 16:04 UTC] degeberg@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 14:01:29 2024 UTC