php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77705 array_search のバグ
Submitted: 2019-03-07 12:21 UTC Modified: 2019-03-07 12:30 UTC
From: giuxon0924 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.3.3 OS: mac
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
13 - 11 = ?
Subscribe to this entry?

 
 [2019-03-07 12:21 UTC] giuxon0924 at gmail dot com
Description:
------------
needleが数字の0の場合、falseになるべきですが、int(0)になる。

Test script:
---------------
# 0の場合
var_dump(array_search(0, ['aa', 'bb']));
int(0) 
↑NG

var_dump(array_search(0, [‘aa’, ‘bb’], true));
bool(false)
↑OK

# 1の場合
var_dump(array_search(1, ['aa', 'bb']));
bool(false)
↑OK

var_dump(array_search(1, [‘aa’, ‘bb’], true));
bool(false)
↑OK

Expected result:
----------------
var_dump(array_search(0, ['aa', 'bb']));
bool(false)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-07 12:29 UTC] kalle@php.net
-Status: Open +Status: Feedback
 [2019-03-07 12:29 UTC] kalle@php.net
Could you please re-phrase the issue in english?
 [2019-03-07 12:30 UTC] nikic@php.net
-Status: Feedback +Status: Not a bug
 [2019-03-07 12:30 UTC] nikic@php.net
var_dump(0 == 'aa'); // bool(true)

See also https://wiki.php.net/rfc/string_to_number_comparison.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC