Edit report at http://bugs.php.net/bug.php?id=30473&edit=1

 ID:                 30473
 Updated by:         johan...@php.net
 Reported by:        lenar at city dot ee
 Summary:            in_array not working correctly
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   Debian
 PHP Version:        4.3.9
 Block user comment: N

 New Comment:

in_array has a third parameter to be strict since PHP 4.2.0.


Previous Comments:
------------------------------------------------------------------------
[2010-08-12 14:27:24] alpust at gmail dot com

So,



$array_symbols = array(0, '1', '5', 'abc', '<', 'hello');

print in_array('z', $array_symbols);



Result: 1



does it normal?

------------------------------------------------------------------------
[2004-10-19 13:38:18] lenar at city dot ee

Trying this as feature request to get review...

------------------------------------------------------------------------
[2004-10-19 13:36:14] lenar at city dot ee

One more comment.



What I want to say is that comparisons in array functions should happen
like 'eq' operator does it in perl.



That would be intuitive. You can't change this, I presume, but that
would be the correct way IMHO.

------------------------------------------------------------------------
[2004-10-19 11:56:05] lenar at city dot ee

I don't know then. All I'm sure the logic behind string and int
comparison isn't as one would expect from language doing automatic type
conversions.



You should cast (string) to (int) or (float) only if (string) is
numeric. Otherwise it's only logical to cast (int)/(float) operand to
string before comparing. That's how I would expect automatic type
conversion behave. Currently it's not intuitive.



("test" == 0) evaluating to true just doesn't seem right.



Just my $0.02 (which I do not have).

------------------------------------------------------------------------
[2004-10-19 09:13:42] der...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

There is no BC here, I tried a couple of versions (4.0.0, 4.0.7, 4.1.2,
4.2.3, 4.3.5-4.3.9) and all do this:



der...@tequila:/dat/dev/php/php-4.0.0$ ./php

<?php

var_dump(in_array("test", array(0)));

?>

X-Powered-By: PHP/4.0.0

Content-type: text/html



bool(true)





------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=30473


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=30473&edit=1

Reply via email to