mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
- Fix error handling
This commit is contained in:
parent
b0f5c889fe
commit
ff88449c31
1 changed files with 30 additions and 6 deletions
|
@ -389,6 +389,7 @@ PHP_FUNCTION(spl_autoload_call)
|
||||||
Register given function as __autoload() implementation */
|
Register given function as __autoload() implementation */
|
||||||
PHP_FUNCTION(spl_autoload_register)
|
PHP_FUNCTION(spl_autoload_register)
|
||||||
{
|
{
|
||||||
|
char *error = NULL;
|
||||||
zval zfunc_name, ztmp;
|
zval zfunc_name, ztmp;
|
||||||
zval *zcallable = NULL;
|
zval *zcallable = NULL;
|
||||||
zend_bool do_throw = 1;
|
zend_bool do_throw = 1;
|
||||||
|
@ -424,34 +425,49 @@ PHP_FUNCTION(spl_autoload_register)
|
||||||
zval_dtor(&ztmp);
|
zval_dtor(&ztmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!zend_is_callable_ex(zcallable, IS_CALLABLE_STRICT, &zfunc_name, &alfi.ce, &alfi.func_ptr, &obj_ptr TSRMLS_CC)) {
|
if (!zend_is_callable_ex(zcallable, IS_CALLABLE_STRICT, &zfunc_name, &alfi.ce, &alfi.func_ptr, &obj_ptr, &error TSRMLS_CC)) {
|
||||||
if (Z_TYPE_P(zcallable) == IS_ARRAY) {
|
if (Z_TYPE_P(zcallable) == IS_ARRAY) {
|
||||||
if (!obj_ptr && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
|
if (!obj_ptr && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
|
||||||
if (do_throw) {
|
if (do_throw) {
|
||||||
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array specifies a non static method but no object");
|
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array specifies a non static method but no object (%s)", error);
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
efree(error);
|
||||||
}
|
}
|
||||||
zval_dtor(&zfunc_name);
|
zval_dtor(&zfunc_name);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
else if (do_throw) {
|
else if (do_throw) {
|
||||||
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "");
|
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error);
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
efree(error);
|
||||||
}
|
}
|
||||||
zval_dtor(&zfunc_name);
|
zval_dtor(&zfunc_name);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
} else if (Z_TYPE_P(zcallable) == IS_STRING || Z_TYPE_P(zcallable) == IS_UNICODE) {
|
} else if (Z_TYPE_P(zcallable) == IS_STRING || Z_TYPE_P(zcallable) == IS_UNICODE) {
|
||||||
if (do_throw) {
|
if (do_throw) {
|
||||||
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function '%R' not %s", Z_TYPE_P(zcallable), Z_UNIVAL_P(zcallable), alfi.func_ptr ? "callable" : "found");
|
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function '%R' not %s, (%s)", Z_TYPE_P(zcallable), Z_UNIVAL_P(zcallable), alfi.func_ptr ? "callable" : "found", error);
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
efree(error);
|
||||||
}
|
}
|
||||||
zval_dtor(&zfunc_name);
|
zval_dtor(&zfunc_name);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
} else {
|
} else {
|
||||||
if (do_throw) {
|
if (do_throw) {
|
||||||
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Illegal value passed");
|
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Illegal value passed (%s)", error);
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
efree(error);
|
||||||
}
|
}
|
||||||
zval_dtor(&zfunc_name);
|
zval_dtor(&zfunc_name);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (error) {
|
||||||
|
efree(error);
|
||||||
|
}
|
||||||
|
|
||||||
zend_u_str_tolower(Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name));
|
zend_u_str_tolower(Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name));
|
||||||
if (SPL_G(autoload_functions) && zend_u_hash_exists(SPL_G(autoload_functions), Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name)+1)) {
|
if (SPL_G(autoload_functions) && zend_u_hash_exists(SPL_G(autoload_functions), Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name)+1)) {
|
||||||
|
@ -512,6 +528,7 @@ skip:
|
||||||
Unregister given function as __autoload() implementation */
|
Unregister given function as __autoload() implementation */
|
||||||
PHP_FUNCTION(spl_autoload_unregister)
|
PHP_FUNCTION(spl_autoload_unregister)
|
||||||
{
|
{
|
||||||
|
char *error = NULL;
|
||||||
zval zfunc_name;
|
zval zfunc_name;
|
||||||
zval *zcallable;
|
zval *zcallable;
|
||||||
zstr lc_name;
|
zstr lc_name;
|
||||||
|
@ -523,10 +540,17 @@ PHP_FUNCTION(spl_autoload_unregister)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!zend_is_callable_ex(zcallable, IS_CALLABLE_CHECK_SYNTAX_ONLY, &zfunc_name, NULL, NULL, &obj_ptr TSRMLS_CC)) {
|
if (!zend_is_callable_ex(zcallable, IS_CALLABLE_CHECK_SYNTAX_ONLY, &zfunc_name, NULL, NULL, &obj_ptr, &error TSRMLS_CC)) {
|
||||||
|
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Unable to unregister invalid function (%s)", error);
|
||||||
|
if (error) {
|
||||||
|
efree(error);
|
||||||
|
}
|
||||||
zval_dtor(&zfunc_name);
|
zval_dtor(&zfunc_name);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
if (error) {
|
||||||
|
efree(error);
|
||||||
|
}
|
||||||
|
|
||||||
lc_name = zend_u_str_tolower_dup(Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name));
|
lc_name = zend_u_str_tolower_dup(Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue