Static Methods

PHOTO EMBED

Wed Aug 25 2021 11:54:18 GMT+0000 (UTC)

Saved by @dinovas #php

<?php 

class User {
    public $name;
    public $age;
    public static $minPassLength = 6;

    public static function  validatePass($pass){
        if(strlen($pass) >= self::$minPassLength) { //self because it's static
            return true;
        } else {
            return false;
        }

    }
}
$password = 'hello';
if(User::validatePass($password)) {
    echo 'Password valid';

} else {
    echo 'Password not valid';
}
content_copyCOPY