#20681 [Com]: array_search(:object, :array) fails
| From: | dparks at verinform dot com | Date: | Wed, 27 Nov 2002 17:48:57 +0000 |
| Subject: | #20681 [Com]: array_search(:object, :array) fails | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-25981@lists.php.net to get a copy of this message | ||
ID: 20681
Comment by: dparks@verinform.com
Reported By: dparks@verinform.com
Status: Open
Bug Type: Arrays related
Operating System: Win 2K SP3
PHP Version: 4.2.3
New Comment:
<?php
class A {
function A () {
}
}
class B {
function B () {
}
}
$g_b = new B ();
$g_array = array (
array ( new A () ),
array ( 'test' ),
array ( $g_b ) );
$g_key = array_search(array ( new A () ), $g_array);
var_dump($g_key);
$g_key = array_search(array ( $g_b ), $g_array);
var_dump($g_key);
$g_key = array_search(array ( 'test' ), $g_array);
var_dump($g_key);
?>
Seems to work as I exect it to:
int(0)
int(2)
int(1)
Also, the original example still produces warnings and doesn't find the
elements if you change the array_search() calls to in_array().
Previous Comments:
------------------------------------------------------------------------
[2002-11-27 11:41:45] dparks@verinform.com
array_search() does not seem to work when the needle is an object.
Sample code:
<?php
class A {
function A () {
}
}
class B {
function B () {
}
}
$g_b = new B ();
$g_array = array ( new A (), 'test', $g_b );
$g_key = array_search(new A (), $g_array);
var_dump($g_key);
$g_key = array_search($g_b, $g_array);
var_dump($g_key);
$g_key = array_search('test', $g_array);
var_dump($g_key);
?>
Output:
<br />
<b>Warning</b>: Wrong datatype for first argument in call to
array_search in <b>C:\dparks\Documents\html\tmp.php</b> on line
<b>17</b><br />
bool(false)
<br />
<b>Warning</b>: Wrong datatype for first argument in call to
array_search in <b>C:\dparks\Documents\html\tmp.php</b> on line
<b>20</b><br />
bool(false)
int(1)
Environment:
This is PHP 4.2.3 (binary from Zend or PHP.net) running on Apache
2.0.40 on Win 2K SP3.
Please email me if you would like me to run more tests, or try another
build (it may be awhile before I can try another build though --
someone else here had trouble with 4.3rc1 and I am behind schedule).
Thanks,
Daniel
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20681&edit=1