php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15201 ('foo'==0) => equal ?
Submitted: 2002-01-24 06:15 UTC Modified: 2002-01-24 06:20 UTC
From: alberty at neptunelabs dot de Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.0CVS-2002-01-24 OS: i688-gnu-linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
8 + 38 = ?
Subscribe to this entry?

 
 [2002-01-24 06:15 UTC] alberty at neptunelabs dot de
A simple condition with a strange result:


<?php
$a='foo';
$b=0;
if ($a==$b) echo 'equal';
else echo 'not equal';
?>

result: $a and $b is equal,
but if $b unequal zero
the condition results 'not equal'

This is not really rationally.

Is the problem the automatic type casting?


Regards,

Steve

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-24 06:20 UTC] derick@php.net
It's indeed due to automatic conversion. The vars get converted to ints, and the integer value of 'foo' = 0
Use if ($a === $b) to check for both value and type.

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 08:01:30 2024 UTC