-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_7.php
60 lines (48 loc) · 1.34 KB
/
2_7.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
//STATIC METHODS & PROPERTIES
//Static properties/methods are relevant to the CLASS not an instance, they are CLASS globals
class User {
private $name;
private $age;
private $pass;
public static $minPassLength = 6;
public function __construct($name, $age, $pass){
$this->name = $name;
$this->age = $age;
$this->pass = $pass;
}
// For static properties/methods use self:: instead of $this->
public static function validatePass($pass){
return (strlen($pass) >= self::$minPassLength) ? true : false;
}
//GETTERS
function __get ($property){
if (property_exists($this, $property)){
return $this->$property;
}
return;
}
//SETTERS
function __set($property, $value){
if (property_exists($property, $value)){
$this->$property = $value;
}
return $this;
}
}
// $user1 = new User ('Bob', 35, 'Ganga ');
// echo $user1->__get('name');
// echo '<br>';
// echo $user1->__get('age');
// echo '<br>';
// echo $user1->__get('pass');
// echo '<br>';
// echo 'Min pass lenght is: '. User::$minPassLength;
// echo '<br>';
// $pass = $user1->__get('pass');
// echo 'Password ';
// echo (User::validatePAss($pass)) ? ' is':' is NOT';
// echo ' OK';
//We can use static fucntions witout instantiating an object
$pass = 'Karam';
echo (User::validatePass($pass)? 'Pass valid' : 'Pass NOT valid');