Re: New exceptions mechanism
| From: | Adam Bregenzer | Date: | Wed, 04 Feb 2004 02:54:40 +0000 |
| Subject: | Re: New exceptions mechanism | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7526@lists.php.net to get a copy of this message | ||
On Tue, 2004-02-03 at 20:14, Alan Knowles wrote:
> It is a slightly annoying limitation.. - inherited static methods, cant
> guess their called class...
> I did look at a fix a while ago - it involved adding a pointer to the
> called class name string, to the exectuter globals, whenever a
> function is called in the engine... - then to retrieve it became
> problematic as
> - you cant really use a function as then it would assign the value again.
> - no-one was too keen to have 'dynamic' constants...
>
> Actually - I AFAIR someone said that it may be fixed in PHP5 back then
> :) - or suggested debug_backtrace.. (but I'm not sure if that is feasible)
It would seem that having $this set in a static method would be the best
way to solve this. What is interesting is that static variables in a
method seem to be scoped to a class, even when inherited. For example:
class Foo {
function & getStaticVar($var) {
static $static_variables;
return $static_variables[$var];
}
}
class Bar extends Foo {
}
$foo_foo = & Foo::getStaticVar('foo');
$bar_foo = & Bar::getStaticVar('foo');
$foo_foo = 1;
$bar_foo = 2;
// And so
(Foo::getStaticVar('foo') != Bar::getStaticVar('foo')) == TRUE
I use this to have static variables without having to define
getStaticVar in every class I use. Since this works it would seem there
is some static context for classes somewhere. Is there a plan to
implement static variables in php5? If so there would be good reason
for $this to be set for static methods in a class. If this were true I
could use class_name($this) in a static method to achieve what I am
looking for.
If there is no current effort to implement static variables I would be
willing to make a go at it, if no one is opposed and there is still time
to add it to php5...
--
Adam Bregenzer
adam@bregenzer.net
http://adam.bregenzer.net/