# __call_static() Magic Method

- Thread: https://externals.io/message/30898
- Original archive: https://news-web.php.net/php.internals/30898
- Started by Sara Golemon on 2007-07-14T00:53:44+00:00
- Messages: 10
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #30898 — Sara Golemon — 2007-07-14T00:53:44+00:00

URL: https://externals.io/message/30898#30898

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

---

## #30904 — Jani Taskinen — 2007-07-14T06:36:11+00:00

URL: https://externals.io/message/30898#30904 · In reply to: #30898

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

---

## #30906 — Sebastian Bergmann — 2007-07-14T06:45:36+00:00

URL: https://externals.io/message/30898#30906 · In reply to: #30904

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

---

## #30910 — Stanislav Malyshev — 2007-07-14T07:02:03+00:00

URL: https://externals.io/message/30898#30910 · In reply to: #30906

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:
> > […]
> 
>  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

---

## #30913 — Jani Taskinen — 2007-07-14T07:19:42+00:00

URL: https://externals.io/message/30898#30913 · In reply to: #30910

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:
> > […]

---

## #30914 — Stanislav Malyshev — 2007-07-14T07:22:54+00:00

URL: https://externals.io/message/30898#30914 · In reply to: #30913

> 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

---

## #30921 — Thomas Moenicke — 2007-07-14T10:30:07+00:00

URL: https://externals.io/message/30898#30921 · In reply to: #30898

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

---

## #30935 — Sara Golemon — 2007-07-14T17:11:49+00:00

URL: https://externals.io/message/30898#30935 · In reply to: #30921

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

---

## #31078 — Sara Golemon — 2007-07-19T06:43:44+00:00

URL: https://externals.io/message/30898#31078 · In reply to: #30898

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

---

## #31281 — Sebastian Deutsch — 2007-07-26T15:23:08+00:00

URL: https://externals.io/message/30898#31281 · In reply to: #30898

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
