php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11401 conditional for non existant variables returns TRUE
Submitted: 2001-06-11 13:38 UTC Modified: 2001-06-12 03:21 UTC
From: ronen at greyzone dot com Assigned:
Status: Closed Package: Variables related
PHP Version: 4.0.4pl1 OS: Red Hat Linux release 6.1 (Cartm
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:
27 - 24 = ?
Subscribe to this entry?

 
 [2001-06-11 13:38 UTC] ronen at greyzone dot com
If there is a conditional on a non-existant (not-set)
variable, it returns an automatic true, instead of an
automatic false.

Examples: (assume that $myVar has never been set)

1. if ($myVar) echo "hello!";  <-- this does echo 'hello'
2. if ($myVar == "42") echo "babel";  <-- this echoes 'babel'
3.
  switch ($myVar) {
    case "42":
      echo "babel";

    default:
      echo "fish";
  } 

  the above example echoes "babel" (!!).

I am aware that I should actually check for isset ($myVar),
but these examples are all from legacy code that I looked at
and that have suddenly started to produce the opposite
result as desired.  What I have described is still a bug,
since a non existant variable should never return true when
compared to a scalar.

Thanks for your help,
Ronen.

PS:
This seems to have appeared with PHP4.04pl1.
Also, I can send you our php.ini file, if needed.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-12 03:21 UTC] sniper@php.net
I can not reproduce this with PHP 4.0.6RC3.
Please try it out:

http://www.php.net/~andi/php-4.0.6RC3.tar.gz

--Jani

 [2001-06-12 03:21 UTC] sniper@php.net
I can not reproduce this with PHP 4.0.6RC3.
Please try it out:

http://www.php.net/~andi/php-4.0.6RC3.tar.gz

--Jani

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 15:01:30 2024 UTC