From d608181dc79fd65579f7cce171a35e027957887e Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Thu, 28 Jul 2005 20:59:44 +0000 Subject: [PATCH] - Allow static loader functions (but only for 5.1.1 as discussed with Andi) --- ext/spl/php_spl.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 900c0974e70..37e18c40f3d 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -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); @@ -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); @@ -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;