php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74794 Strange bug where n/a == 0
Submitted: 2017-06-21 14:50 UTC Modified: 2017-06-21 15:13 UTC
From: azamorn at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.2.0alpha1 OS: Linux & Windows
Private report: No CVE-ID: None
 [2017-06-21 14:50 UTC] azamorn at gmail dot com
Description:
------------
I've tested the code on multiple versions of PHP, no matter where I test I get the same strange behaviour, actually really curious as to how this is even possible.

It evaluates 'n/a' == 0

Even though they are obviously not the same thing.

In the demo script the bug happens on the second option where I check whether the posted value is the same as the field value and if true I output 'selected'

What you would expect to happen on load is that only the default value would be selected, however for some strange reason both 0 and n/a == n/a

This code has been tested on at least 3 different machines, including on my own server here at https://www.differentiality.co.za, where I'm running the latest released version of PHP straight from apt-get.

Please do contact me if I can be of any more assistance.

Test script:
---------------
I've posted a link to the page where the bug can be reproduced at PhpFiddle
http://phpfiddle.org/main/code/4sr3-cq2w

Expected result:
----------------
<option data-comparevalue="n/a" data-value="n/a" selected value="n/a">Please Select</option>
<option data-comparevalue="0" data-value="n/a" value="0">Please Select</option>

Actual result:
--------------
<option data-comparevalue="n/a" data-value="n/a" selected value="n/a">Please Select</option>
<option data-comparevalue="0" data-value="n/a" selected value="0">Please Select</option>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-21 15:13 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2017-06-21 15:13 UTC] cmb@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

Especially, see 
<http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.types>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 14:01:30 2024 UTC