note 82629 added to language.oop5.magic
| From: | michaldotkocarekatseznamdotcz at osu1 dot php dot net | Date: | Fri, 18 Apr 2008 21:34:33 +0000 |
| Subject: | note 82629 added to language.oop5.magic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-138519@lists.php.net to get a copy of this message | ||
Remember that setters and getters (__set, __get) will work in your class as long as you NOT SET the
property with given name.
If you still want to have the public property definition in the class source code (phpDocumentor,
editor code completition, or any other reason) when using these magic methods, simply unset() your
public properties inside the constructor.
__set/__get function will be called and code reader will see at first sight, which public properties
are available.
Example:
<?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
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 89.24.234.232
----
Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php
Edit -- https://master.php.net/note/edit/82629
Del: integrated -- https://master.php.net/note/delete/82629/integrated
Del: useless -- https://master.php.net/note/delete/82629/useless
Del: bad code -- https://master.php.net/note/delete/82629/bad+code
Del: spam -- https://master.php.net/note/delete/82629/spam
Del: non-english -- https://master.php.net/note/delete/82629/non-english
Del: in docs -- https://master.php.net/note/delete/82629/in+docs
Del: other reasons-- https://master.php.net/note/delete/82629
Reject -- https://master.php.net/note/reject/82629
Search -- https://master.php.net/manage/user-notes.php