note 97599 added to language.oop5.overloading
| From: | ~A! at osu1 dot php dot net | Date: | Tue, 27 Apr 2010 16:03:22 +0000 |
| Subject: | note 97599 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168728@lists.php.net to get a copy of this message | ||
Dynamic getting-setting using __call and __callStatic
<?php
class A {
private $fields;
public function __call($func, $args) {
if (empty($args)) {
return $this->fields[$args[0]];
} else {
$this->$fields[$func] = $args[0];
}
}
?>
Or statically:
<?php
class foo {
static $vals;
public static function __callStatic($func, $args) {
if (!empty($args)) {
self::$vals[$func] = $args[0];
} else {
return self::$vals[$func];
}
}
}
?>
Which would allow you to say:
<?php
Foo::username('john');
print Foo::username(); // prints 'john'
?>
----
Server IP: 69.147.83.197
Probable Submitter: 96.39.4.134
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/97599
Del: integrated -- https://master.php.net/note/delete/97599/integrated
Del: useless -- https://master.php.net/note/delete/97599/useless
Del: bad code -- https://master.php.net/note/delete/97599/bad+code
Del: spam -- https://master.php.net/note/delete/97599/spam
Del: non-english -- https://master.php.net/note/delete/97599/non-english
Del: in docs -- https://master.php.net/note/delete/97599/in+docs
Del: other reasons-- https://master.php.net/note/delete/97599
Reject -- https://master.php.net/note/reject/97599
Search -- https://master.php.net/manage/user-notes.php