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
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: alberty at neptunelabs dot de
New email:
PHP Version: OS:

 

 [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: Thu Apr 25 12:01:31 2024 UTC