php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78336 Error compare zero with array[n]
Submitted: 2019-07-26 16:10 UTC Modified: 2019-07-26 16:13 UTC
From: lucastiagodemoraes at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 7.2.20 OS: Ubuntu 18.04
Private report: No CVE-ID: None
 [2019-07-26 16:10 UTC] lucastiagodemoraes at gmail dot com
Description:
------------
Hi guys,
See example of bug you will understand. 
If this is normal in PHP is very strange. Thanks.

Test script:
---------------
<?php
$letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');

print 0 == $letters[0] ? $letters[0] : 'false';
print 0 == $letters[1] ? $letters[1] : 'false';
print 0 == $letters[2] ? $letters[2] : 'false';
print 0 == $letters[3] ? $letters[3] : 'false';
print 0 == $letters[4] ? $letters[4] : 'false';

Expected result:
----------------
falsefalsefalsefalsefalse

Actual result:
--------------
abcde

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-26 16:13 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-07-26 16:13 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

https://www.php.net/manual/en/language.operators.comparison.php
https://www.php.net/manual/en/language.types.type-juggling.php
https://www.php.net/manual/en/types.comparisons.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC