Skip to content

Instantly share code, notes, and snippets.

@cythrawll
Created May 21, 2013 04:04
Show Gist options
  • Save cythrawll/5617412 to your computer and use it in GitHub Desktop.
Save cythrawll/5617412 to your computer and use it in GitHub Desktop.
#include "php_sample.h"
#define CODEANGEL_NS "CodeAngel"
PHP_FUNCTION(sample_hello_world)
{
php_printf("Hello World!\n");
}
static const zend_function_entry php_sample_functions[] = {
ZEND_NS_NAMED_FE(CODEANGEL_NS, helloWorld, ZEND_FN(sample_hello_world), NULL)
PHP_FE_END
};
zend_module_entry sample_module_entry = {
STANDARD_MODULE_HEADER,
PHP_SAMPLE_EXTNAME,
php_sample_functions, /* functions */
NULL, /* MINIT */
NULL, /* MSHUTDOWN */
NULL, /* RINIT */
NULL, /* RSHUTDOWN */
NULL, /* MINFO */
PHP_SAMPLE_EXTVER,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_SAMPLE
ZEND_GET_MODULE(sample)
#endif
@cythrawll
Copy link
Author

when I:

var_dump(get_extension_funcs("sample"));

I get:

array(1) {
  [0]=>
  string(22) "CodeAngel\"helloWorld""
}

with weird quotes around the function name. calling:

CodeAngel\helloWorld();

throws a function not found error.

using ZEND_NS_FE seems to work, but I wanted to use ZEND_NS_NAMED_FE to control the name of my functions.

@cythrawll
Copy link
Author

had Derick help me a bit

ZEND_NS_RAW_FENTRY(CODEANGEL_NS, "helloWorld", ZEND_FN(sample_hello_world), NULL, 0)

works

seems ZEND_NS_NAMED_FE is borked.

@sgolemon
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment