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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 23:01:29 2024 UTC