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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Mon Dec 30 17:01:29 2024 UTC