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
 [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-2021 The PHP Group
All rights reserved.
Last updated: Sun Apr 11 04:01:24 2021 UTC