[php-src] Issue #7922: `print_r` should not produce a fatal error

From: Date: Mon, 10 Jan 2022 16:27:31 +0000
Subject: [php-src] Issue #7922: `print_r` should not produce a fatal error
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238936@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7922 Comment Author: cmb69 Yeah, [that zend_error_noreturn()](https://github.com/php/php-src/blob/master/Zend/zend_object_handlers.c#L182) looks overly strict, especially since return NULL would be accepted and properly handled. We could treat other return types likely like NULL: ````diff Zend/zend_object_handlers.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 28d0077878..f1e3c46299 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -150,7 +150,8 @@ ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) / } zend_call_known_instance_method_with_0_params(ce->__debugInfo, object, &retval); - if (Z_TYPE(retval) == IS_ARRAY) { + switch (Z_TYPE(retval)) { + case IS_ARRAY: if (!Z_REFCOUNTED(retval)) { *is_temp = 1; return zend_array_dup(Z_ARRVAL(retval)); @@ -163,14 +164,15 @@ ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) / zval_ptr_dtor(&retval); return Z_ARRVAL(retval); } - } else if (Z_TYPE(retval) == IS_NULL) { + default: + zend_throw_error(NULL, ZEND_DEBUGINFO_FUNC_NAME "() must return an array"); + /* fallthrough */ + case IS_NULL: *is_temp = 1; ht = zend_new_array(0); return ht; } - zend_error_noreturn(E_ERROR, ZEND_DEBUGINFO_FUNC_NAME "() must return an array"); - return NULL; /* Compilers are dumb and don't understand that noreturn means that the function does NOT need a return value... */ } /* }}} */ ```` (improper indentation to simply the diff)

« previous php.bugs (#238936) next »