I'm trying to access php class from another file:
$john = new User();
$john->setPassword('123');
var_dump($john);
this class code works fine with all exceptions, when pass length < 8
class User
{
...
public $password;
const MINCHARS = 8;
...
public function setPassword($string){
if(strlen($string) < self::MINCHARS){
throw new Exception("pass must be at least ". self::MINCHARS . 'chars long');
}else{
$this->password = hash('sha256', $string);
}
}
but if I change if statement to (without self::)
if(strlen($string) < MINCHARS)
and access the class as usual
flow goes silently to else clause without any error or exception and in browser I see pretty good string
object(User)#1 (2) { ["email"]=> string(10) "john@email" ["password"]=> string(64) "a5b432ee0307be7fa23aa00461f54eee34ba9d45251b5504567d37a8da339dff" }
why "if" thinks that it is true in this case?
version PHP is:
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.3
works on embedded server
php -S localhost:8080