justpersian
Member
سلام .
به نقل از سایت php :
می خواستم بدونم توابع set__ و get__ که تو خود سایت PHP هم توابع جادویی معرفی شده چه کاربردی دارند ؟
نمونه کد :
ممنون 
به نقل از سایت php :
The function names
__construct, __destruct, __call, __callStatic, __get, __set, __isset, __unset, __sleep, __wakeup, __toString, __invoke, __set_state and __clone
are magical in PHP classes
می خواستم بدونم توابع set__ و get__ که تو خود سایت PHP هم توابع جادویی معرفی شده چه کاربردی دارند ؟
نمونه کد :
PHP:
<?php
class user {
/**
* @var int Gets and sets the user ID
*/
public $UserID;
private $_userID;
public function __construct() {
// All the magic is in single line:
// We unset public property, so our setters and getters
// are used and phpDoc and editors with code completition are happy
unset($this->UserID);
}
public function __set($key, $value) {
// assign value for key UserID to _userID property
}
public function __get($key) {
// return value of _userID for UserID property
}
}
?>

آخرین ویرایش: