php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10491 $this->AuthTblCols[$colname] == 0 => false
Submitted: 2001-04-25 10:54 UTC Modified: 2001-07-15 14:08 UTC
From: angulion at gatefive dot fi Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: SuSE 6.2 / Linux 2.4.2
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: angulion at gatefive dot fi
New email:
PHP Version: OS:

 

 [2001-04-25 10:54 UTC] angulion at gatefive dot fi
Short:
In a class "if ($this->arr[$keyname] != 0);" will allways be false.

Long:
<?
class Auth {
  var $AuthTblCols = array('login'      => 'login',
                           'passwd'     => 'passwd',
                           'access_lvl' => 0,
                           'last_login' => 0);

//.... snip ....
   function ColOK($colname, $str) {
    print_r("<pre>ColOK:");  var_dump($this->AuthTblCols[$colname]);print_r("</pre>"); 
/* returns string 'access_lvl' (see under) */
      if (!empty($this->AuthTblCols[$colname]) &&

          !($this->AuthTblCols[$colname] == 0)
/* The Line above will allways evaluate false!!?!
at first I had:
$this->AuthTblCols[$colname] != 0
But it also evaluates false.*/
      ) {
print_r("HERE");
         return (empty($str)?true:$str);
      }
      return false;
   }
    function somefunc() {
// a func inside the class will call ColOK()
      if (!$str = $this->ColOK('access_lvl', 
                               "somestring I want returned")) echo "Not ok";
//.... snip ....
}

$auth = new Auth();
$auth->AuthTblCols = array('login'      => 'login',
                           'passwd'     => 'passwd',
                           'access_lvl' => 'access_lvl',
                           'last_login' => 'last_login');
if (!$auth->A_func_that_will_run_somefunc()) {
  echo "Invalid login/password";
  exit;
}
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-15 14:08 UTC] zeev@php.net
This behavior is by design.
If you compare strings and integers, a numeric comparison will be performed.  In order to check for a non empty string, you can use:
if (!empty($var))
if ($var)
if ($var==="")
if (!strcmp($var, ""))

depending on what you want.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Jan 26 14:01:24 2020 UTC