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
 [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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 17:01:31 2024 UTC