php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #30399 "Comparing strings" manual page
Submitted: 2004-10-11 17:40 UTC Modified: 2004-10-15 09:16 UTC
From: techtonik@php.net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.3.9 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: techtonik@php.net
New email:
PHP Version: OS:

 

 [2004-10-11 17:40 UTC] techtonik@php.net
Description:
------------
After studying some string issues I think we need one more page in manual about strings comparison with a link to/from strcmp. Few confusing examples from user-notes on http://www.php.net/manual/en/language.types.string.php

And I haven't found any clear answer about is === operator equal to strcmp() if two arguments are strings with numbers in the beginning? 

Many coders use "==" instead of "strcmp" and there should be warning somewhere in manual about possible problems that could arise due to such misuse.

See also: 
http://bugs.php.net/bug.php?id=28200

Reproduce code:
---------------
<?php
$x1 = '111111111111111111';
$x2 = '111111111111111112';
echo ($x1 == $x2) ? "true\n" : "false\n"; //true
?>

<?
$hello='hi there';
echo($hello?'true':'false');         //true
echo($hello==0?'true':'false');      //true!!!!!
echo($hello===0?'true':'false');     //false
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-12 10:15 UTC] vrana@php.net
"Is === operator equal to strcmp() if two arguments are strings with numbers in the beginning?"

They are equivalent AFAIK.

"Many coders use "==" instead of "strcmp" and there should be warning somewhere in manual about possible problems that could arise due to such misuse."

There is "If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. These rules also apply to the switch statement." in language.operators.comparison.

I think this bug can be marked as bogus.

 [2004-10-15 09:16 UTC] vrana@php.net
Already documented.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Oct 21 10:01:25 2020 UTC