Skip to content

Commit

Permalink
- Allow static loader functions (but only for 5.1.1 as discussed with…
Browse files Browse the repository at this point in the history
… Andi)
  • Loading branch information
helly25 committed Jul 28, 2005
1 parent 53e5260 commit d608181
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions ext/spl/php_spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,33 @@ PHP_FUNCTION(spl_autoload_call)
Register given function as __autoload() implementation */
PHP_FUNCTION(spl_autoload_register)
{
char *func_name, *lc_name;
char *func_name, *lc_name = NULL;
zval *zcallable = NULL;
int func_name_len;
zend_bool do_throw = 1;
zend_function *spl_func_ptr, *func_ptr, **func_ptr_ptr;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sb", &func_name, &func_name_len, &do_throw) == FAILURE) {
return;
}

if (ZEND_NUM_ARGS()) {
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "|sb", &func_name, &func_name_len, &do_throw) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &zcallable, &func_name_len, &do_throw) == FAILURE) {
return;
}
#if MBO_0
if (!zend_is_callable_ex(zcallable, IS_CALLABLE_CHECK_IS_STATIC, &func_name, &func_name_len, &func_ptr, NULL TSRMLS_CC)) {
if (do_throw) {
if (func_ptr) {
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Non static methods are not supported yet");
} else {
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify a callable method or method");
}
}
return;
}
lc_name = do_alloca(func_name_len + 1);
zend_str_tolower_copy(lc_name, func_name, func_name_len);
#else
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Loader methods are not yet supported");
#endif
} else if (ZEND_NUM_ARGS()) {
lc_name = do_alloca(func_name_len + 1);
zend_str_tolower_copy(lc_name, func_name, func_name_len);

Expand All @@ -384,7 +401,9 @@ PHP_FUNCTION(spl_autoload_register)
free_alloca(lc_name);
return;
}

}

if (ZEND_NUM_ARGS()) {
if (!SPL_G(autoload_functions)) {
ALLOC_HASHTABLE(SPL_G(autoload_functions));
zend_hash_init(SPL_G(autoload_functions), 1, NULL, NULL, 0);
Expand Down Expand Up @@ -473,7 +492,19 @@ PHP_FUNCTION(spl_autoload_functions)
zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos);
while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) {
zend_hash_get_current_data_ex(SPL_G(autoload_functions), (void **) &func_ptr_ptr, &function_pos);
add_next_index_string(return_value, (*func_ptr_ptr)->common.function_name, 1);
#if MBO_0
if ((*func_ptr_ptr)->common.scope) {
zval *tmp;
MAKE_STD_ZVAL(tmp);
array_init(tmp);

add_next_index_string(tmp, (*func_ptr_ptr)->common.scope->name, 1);
add_next_index_string(tmp, (*func_ptr_ptr)->common.function_name, 1);
add_next_index_zval(return_value, tmp);
} else
#endif
add_next_index_string(return_value, (*func_ptr_ptr)->common.function_name, 1);

zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos);
}
return;
Expand Down

0 comments on commit d608181

Please sign in to comment.