php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #561 if($var) behavior changed when $var=0
Submitted: 1998-07-19 23:03 UTC Modified: 1998-07-20 00:03 UTC
From: whit at transpect dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.1 OS: Redhat Linux 5.0 & 5.1
Private report: No CVE-ID: None
 [1998-07-19 23:03 UTC] whit at transpect dot com
In php 3.0, checking for the existence of a variable with if($var) succeeded when the variable equalled zero. In 3.0.1 it does not. I can see the argument that it should fail - but it has been quite useful to have it succeed (as compared to times when that variable isn't present - I use this a lot so that a script knows it has been called for a function whenever the variable it would use in that function is set - and often the variable tells it which position in an array to act on, thus it's often enough 0). Is this configurable somewhere? 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-07-20 00:03 UTC] zeev
Hmm, that's not true.  No such change was made between 3.0
and 3.0.1, or at all.
0 always meant false, and if(0) always failed.

Somewhere in the beta line, "0" changed meaning from false
to true and then back to false.  Eventually, it means
false, and this isn't going to change.
The truth value of variables isn't there to determine
whether the variable exists or not, but whether it means
true or false.  To determine if a variable exists or not,
you should use isset().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 07:01:30 2024 UTC