3

On writing an extension for php (5.3) i want to access the zend_class_entry pointer on a static method.

On non static methods i can use the getThis() macro and within Z_OBJCE_P macro like this:

zend_class_entry ce* = Z_OBJCE_P(getThis());

Now the problem: on static methods the getThis() macro returns a null pointer, so i can not use the Z_OBJCE_P macro.

Has anyone a solution for me to access the zend_class_entry from a static method??

Charles
  • 50,943
  • 13
  • 104
  • 142
sassman
  • 81
  • 5

1 Answers1

3

it is really interesting: on static methods you can access the scope like this

zend_class_entry* ce = 0L;
if (EG(called_scope)) {
    ce = EG(called_scope);
} else if (!EG(scope))  {
    ce = EG(scope);
}

the EG Macro access a lot of global and context specific variables, also the calling scope, the calling class of the static method.

sassman
  • 81
  • 5
  • Note the called scope is not the same as the (calling) scope, the first is related to LSB, the second is probably what you want. – Artefacto Dec 24 '10 at 15:29