note 116236 added to language.oop5.overloading
| From: | gabe at fijiwebdesign dot com | Date: | Thu, 27 Nov 2014 11:33:31 +0000 |
| Subject: | note 116236 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201028@lists.php.net to get a copy of this message | ||
Note that you can enable "overloading" on a class instance at runtime for an existing
property by unset()ing that property.
eg:
<?php
class Test {
public $property1;
public function __get($name)
{
return "Get called for " . get_class($this) . "->\$$name \n";
}
}
?>
The public property $property1 can be unset() so that it can be dynamically handled via __get().
<?php
$Test = new Test();
unset($Test->property1); // enable overloading
echo $Test->property1; // Get called for Test->$property1
?>
Useful if you want to proxy or lazy load properties yet want to have documentation and visibility in
the code and debugging compared to __get(), __isset(), __set() on non-existent inaccessible
properties.
----
Server IP: 72.52.91.14
Probable Submitter: 86.96.96.32
----
Manual Page -- http://php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/116236
Del: integrated -- https://master.php.net/note/delete/116236/integrated
Del: useless -- https://master.php.net/note/delete/116236/useless
Del: bad code -- https://master.php.net/note/delete/116236/bad+code
Del: spam -- https://master.php.net/note/delete/116236/spam
Del: non-english -- https://master.php.net/note/delete/116236/non-english
Del: in docs -- https://master.php.net/note/delete/116236/in+docs
Del: other reasons-- https://master.php.net/note/delete/116236
Reject -- https://master.php.net/note/reject/116236
Search -- https://master.php.net/manage/user-notes.php