Attached is a patch which exports an internals hook in zend_class_entry
for fetching function pointers similar to the object hook get_method()
available to instance methods.
This patch also exports a userspace hook __call_static() which operates
in the fashion of the current __call() magic method, but for static calls.
Wez called for some functionality like this a few weeks ago for a COM
wrapper (or something similar), and I noticed there was actually a
comment in the engine about how this should eventually be done anyway...
Usage example:
class foo
{
public static function __call_static($fname, $args)
{
echo "foo::{$fname}() called staticly with ",
count($args), " parameters\n";
}
}
foo::randomMethod(1,2,3);
I considered setting get_static_method to zend_std_get_static_method()
by default (avoiding the if set check during runtime), but all the other
hoooks follow this pattern so I went with consistency.
If noone comments to the negative, I'll commit next friday (7/20)...
-Sara
Sara Golemon kirjoitti:
Attached is a patch which exports an internals hook in zend_class_entry
for fetching function pointers similar to the object hook get_method()
available to instance methods.This patch also exports a userspace hook __call_static() which operates
in the fashion of the current __call() magic method, but for static calls.Wez called for some functionality like this a few weeks ago for a COM
wrapper (or something similar), and I noticed there was actually a
comment in the engine about how this should eventually be done anyway...Usage example:
class foo
{
public static function __call_static($fname, $args)
{
echo "foo::{$fname}() called staticly with ",
count($args), " parameters\n";
}
}foo::randomMethod(1,2,3);
I considered setting get_static_method to zend_std_get_static_method()
by default (avoiding the if set check during runtime), but all the other
hoooks follow this pattern so I went with consistency.If noone comments to the negative, I'll commit next friday (7/20)...
As long as you MFH, I don't mind.
--Jani
Jani Taskinen schrieb:
As long as you MFH, I don't mind.
Yeah, I would love to have this in PHP_5_2, too. :)
--
Sebastian Bergmann http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
I'm afraid this change is binary incompatible - it changes class
structure, which is in use by extensions. So you'd need 5.3 for that.
Sebastian Bergmann wrote:
Jani Taskinen schrieb:
As long as you MFH, I don't mind.
Yeah, I would love to have this in PHP_5_2, too. :)
--
Stanislav Malyshev, Zend Software Architect
stas@zend.com http://www.zend.com/
(408)253-8829 MSN: stas@zend.com
And there is no reason not to release 5.3 is there?
I'd also like to MFH the namespace patch for PHP 5.
--Jani
Stanislav Malyshev kirjoitti:
I'm afraid this change is binary incompatible - it changes class
structure, which is in use by extensions. So you'd need 5.3 for that.Sebastian Bergmann wrote:
Jani Taskinen schrieb:
As long as you MFH, I don't mind.
Yeah, I would love to have this in PHP_5_2, too. :)
And there is no reason not to release 5.3 is there?
I'd also like to MFH the namespace patch for PHP 5.
well, that's topic for another discussion, I just wanted to remind that
it can't be in PHP_5_2.
Stanislav Malyshev, Zend Software Architect
stas@zend.com http://www.zend.com/
(408)253-8829 MSN: stas@zend.com
This is actually a very good idea. I had to put a hook into the opcode handler
for static method calls to get the same result which is not really elegant. I
was waiting for this feature for a couple month.
Also I found out that the names of the static methods are already lowercase
when it comes to the handler, i don't know if that is fixed in the meanwhile.
On Saturday 14 July 2007 02:53:44 Sara Golemon wrote:
Attached is a patch which exports an internals hook in zend_class_entry
for fetching function pointers similar to the object hook get_method()
available to instance methods.This patch also exports a userspace hook __call_static() which operates
in the fashion of the current __call() magic method, but for static calls.Wez called for some functionality like this a few weeks ago for a COM
wrapper (or something similar), and I noticed there was actually a
comment in the engine about how this should eventually be done anyway...Usage example:
class foo
{
public static function __call_static($fname, $args)
{
echo "foo::{$fname}() called staticly with ",
count($args), " parameters\n";
}
}foo::randomMethod(1,2,3);
I considered setting get_static_method to zend_std_get_static_method()
by default (avoiding the if set check during runtime), but all the other
hoooks follow this pattern so I went with consistency.If noone comments to the negative, I'll commit next friday (7/20)...
-Sara
--
Thomas
Thomas Moenicke wrote:
This is actually a very good idea. I had to put a hook into the opcode handler
for static method calls to get the same result which is not really elegant. I
was waiting for this feature for a couple month.
Also I found out that the names of the static methods are already lowercase
when it comes to the handler, i don't know if that is fixed in the meanwhile.
Not fixed yet, but it certainly is fixable. Good catch. Please bring
up any other brokennesses you notice...
-Sara
Sara Golemon wrote:
Attached is a patch which exports an internals hook in zend_class_entry
for fetching function pointers similar to the object hook get_method()
available to instance methods.This patch also exports a userspace hook __call_static() which operates
in the fashion of the current __call() magic method, but for static calls.Wez called for some functionality like this a few weeks ago for a COM
wrapper (or something similar), and I noticed there was actually a
comment in the engine about how this should eventually be done anyway...Usage example:
class foo
{
public static function __call_static($fname, $args)
{
echo "foo::{$fname}() called staticly with ",
count($args), " parameters\n";
}
}foo::randomMethod(1,2,3);
I considered setting get_static_method to zend_std_get_static_method()
by default (avoiding the if set check during runtime), but all the other
hoooks follow this pattern so I went with consistency.If noone comments to the negative, I'll commit next friday (7/20)...
Updated patch applies, mostly fixing minor bugs in implementation
(include one fix for the __call method as well).
The more significant change from the previous patch it the userspace
name: __callStatic() rather than __call_static(). This is in keeping
with __toString() and the standard of using camel case rather than
underscore demarcation.
-Sara
Hello,
where can i find the latest version of your patch?
Etienne Kneuss provided me a patch to track from where my class method
is called statically.
<?
class foo {
function doit() {
echo get_called_class()
;
}
}
foo::doit(); // with etiennes patch it will echo foo
?>
Will they work together?
cheers
*.sebastian deutsch
Sara Golemon schrieb:
Attached is a patch which exports an internals hook in zend_class_entry
for fetching function pointers similar to the object hook get_method()
available to instance methods.This patch also exports a userspace hook __call_static() which operates
in the fashion of the current __call() magic method, but for static calls.Wez called for some functionality like this a few weeks ago for a COM
wrapper (or something similar), and I noticed there was actually a
comment in the engine about how this should eventually be done anyway...Usage example:
class foo
{
public static function __call_static($fname, $args)
{
echo "foo::{$fname}() called staticly with ",
count($args), " parameters\n";
}
}foo::randomMethod(1,2,3);
I considered setting get_static_method to zend_std_get_static_method()
by default (avoiding the if set check during runtime), but all the other
hoooks follow this pattern so I went with consistency.If noone comments to the negative, I'll commit next friday (7/20)...
-Sara