note 75047 added to language.oop5.overloading
| From: | stephen at one2one3 dot com | Date: | Thu, 10 May 2007 00:58:20 +0000 |
| Subject: | note 75047 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126373@lists.php.net to get a copy of this message | ||
What is the status on using __{get,set,call} statically?
I tried to implement a rails style findBy method using __call, but ended up having to make it
instance-based when i ran into the issues mentioned by yuggoth23 below:
<?php
public function __call($methodName, $methodArguments) {
if (strpos($methodName, 'findBy') === 0) {
$lookupKey = strtolower(substr($methodName, strlen('findBy')));
if ($lookupKey) {
$lookupValue = $methodArguments[0];
$fields = isset($methodArguments[1]) ? $methodArguments[1] : '*';
return $this->findBy($lookupKey, $lookupValue, $fields);
}
}
throw new MethodNotFoundException($methodName);
}
?>
so usage ends up being
<?php
$user = new User();
$user->findByName('joeyjoejoe');
?>
which sucks enough that its not worth using.
I'd also like to access static member variables using __get and that doesn't work either
<?php
class Duh {
function __get($nm) {
echo $nm;
}
}
$d = new Duh();
echo $d->blah;
echo Duh::blah;
echo Duh::blah();
?>
results in:
blah
Undefined class constant 'blah'
Call to undefined method Duh::blah()
Making __get a static method didn't seem to have an effect. Anybody have any clean workarounds
or know of the priority/possibility of these things getting fixed?
There is an existing bug in for this, but it doesn't look like there's been any movement
for awhile.
http://bugs.php.net/bug.php?id=26739
----
Server IP: 69.39.81.135
Probable Submitter: 66.92.187.33
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/75047
Del: integrated -- https://master.php.net/note/delete/75047/integrated
Del: useless -- https://master.php.net/note/delete/75047/useless
Del: bad code -- https://master.php.net/note/delete/75047/bad+code
Del: spam -- https://master.php.net/note/delete/75047/spam
Del: non-english -- https://master.php.net/note/delete/75047/non-english
Del: in docs -- https://master.php.net/note/delete/75047/in+docs
Del: other reasons-- https://master.php.net/note/delete/75047
Reject -- https://master.php.net/note/reject/75047
Search -- https://master.php.net/manage/user-notes.php