php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75750 PHP 7.2.0RC3 (cli) (built: Sep 28 2017 16:28:14) ( NTS )
Submitted: 2017-12-30 22:48 UTC Modified: 2017-12-30 22:59 UTC
From: helldar at ai-rus dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 7.2.0 OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: helldar at ai-rus dot com
New email:
PHP Version: OS:

 

 [2017-12-30 22:48 UTC] helldar at ai-rus dot com
Description:
------------
When searching for an integer "0" in the in_array function that does not contain it as a value, the function always returns true

PHP 7.2.0RC3 (cli) (built: Sep 28 2017 16:28:14) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0-dev, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.2.0RC3, Copyright (c) 1999-2017, by Zend Technologies
    with blackfire v1.18.0~linux-x64-non_zts72, https://blackfire.io, by SensioLabs


Test script:
---------------
$arr = ['Car', 'Images'];
$key = 0;

echo (string)in_array($key, $arr);
// Returned: 1

OR

$arr = ['Car', 'Images'];
$key = 1;

echo (string)in_array($key, $arr);
// Returned: 0


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-30 22:52 UTC] helldar at ai-rus dot com
The bug works in the following versions of PHP: 5.6.29, 7.0.14, 7.1.12 and 7.2.0RC3.
Other versions I did not check.
 [2017-12-30 22:59 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-12-30 22:59 UTC] requinix@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

http://php.net/manual/en/function.in-array.php
> Searches haystack for needle using loose comparison unless strict is set.

https://www.google.com/search?q=php+loose+comparisons

Use in_array($key, $arr, true).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC