Declaring php-class static member functions from within C/C++

php.internals

Andrew Mather

20 years ago
If I define/declare php class methods via: INIT_CLASS_ENTRY(ce, phpclassname, myclassmethods); where myclassmethods is defined as eg: function_entry myclass::myclassmethods[] = { PHP_ME(myclass, __construct, arginfo_Guid__construct, ZEND_ACC_PUBLIC) PHP_ME(myclass, getValue, NULL, ZEND_ACC_PUBLIC) }; then getValue is a member function of an instantiated object, Unsurprisingly, attempting to call myclass::getValue() therefore generates a: "Non-static method myclass::getValue() cannot be called statically" error, even where no dependency on the object (via getThis()) is required. How then can I inform zend/php of my intent to supply a static member function, such that I can call for example myclass::somestaticfunc() I can clearly create global functions, viz: myclass_somestaticfunc() but these would all apparently need to be declared in the module function entry. A neater solution would be to declare static member functions pertinent to the class, either by flagging them as static, or suppling a second function_entry to a 'static member functions *' in class_entry. Php clearly tolerates static member functions in its own php-defined classes. Is there a declaration mechanism available to declare them from within C/C++? Cheers, Andrew.

l0t3k

20 years ago
> How then can I inform zend/php of my intent to supply a static member > function, such that I can call for example myclass::somestaticfunc()
PHP_ME(myclass, getValue, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )

l0t3k

20 years ago
> How then can I inform zend/php of my intent to supply a static member > function, such that I can call for example myclass::somestaticfunc()
PHP_ME(myclass, getValue, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )