Skip to content

Commit c3d1f8e

Browse files
committed
Promote warning to exception in constant() function
1 parent a36aaff commit c3d1f8e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

ext/standard/basic_functions.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ PHP_FUNCTION(constant)
20402040
}
20412041
} else {
20422042
if (!EG(exception)) {
2043-
php_error_docref(NULL, E_WARNING, "Couldn't find constant %s", ZSTR_VAL(const_name));
2043+
zend_value_error("Couldn't find constant %s", ZSTR_VAL(const_name));
20442044
}
20452045
RETURN_NULL();
20462046
}
@@ -3202,7 +3202,7 @@ static int user_shutdown_function_call(zval *zv) /* {{{ */
32023202
if (!zend_is_callable(&shutdown_function_entry->arguments[0], 0, NULL)) {
32033203
zend_string *function_name
32043204
= zend_get_callable_name(&shutdown_function_entry->arguments[0]);
3205-
php_error(E_WARNING, "(Registered shutdown functions) Unable to call %s() - function does not exist", ZSTR_VAL(function_name));
3205+
zend_value_error("(Registered shutdown functions) Unable to call %s() - function does not exist", ZSTR_VAL(function_name));
32063206
zend_string_release_ex(function_name, 0);
32073207
return 0;
32083208
}
@@ -3240,15 +3240,15 @@ static void user_tick_function_call(user_tick_function_entry *tick_fe) /* {{{ */
32403240
zval *obj, *method;
32413241

32423242
if (Z_TYPE_P(function) == IS_STRING) {
3243-
php_error_docref(NULL, E_WARNING, "Unable to call %s() - function does not exist", Z_STRVAL_P(function));
3243+
zend_value_error("Unable to call %s() - function does not exist", Z_STRVAL_P(function));
32443244
} else if ( Z_TYPE_P(function) == IS_ARRAY
32453245
&& (obj = zend_hash_index_find(Z_ARRVAL_P(function), 0)) != NULL
32463246
&& (method = zend_hash_index_find(Z_ARRVAL_P(function), 1)) != NULL
32473247
&& Z_TYPE_P(obj) == IS_OBJECT
32483248
&& Z_TYPE_P(method) == IS_STRING) {
3249-
php_error_docref(NULL, E_WARNING, "Unable to call %s::%s() - function does not exist", ZSTR_VAL(Z_OBJCE_P(obj)->name), Z_STRVAL_P(method));
3249+
zend_value_error("Unable to call %s::%s() - function does not exist", ZSTR_VAL(Z_OBJCE_P(obj)->name), Z_STRVAL_P(method));
32503250
} else {
3251-
php_error_docref(NULL, E_WARNING, "Unable to call tick function");
3251+
zend_value_error("Unable to call tick function");
32523252
}
32533253
}
32543254

ext/standard/tests/general_functions/bug72920.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ class Foo {
66
private const C1 = "a";
77
}
88

9-
var_dump(constant('Foo::C1'));
9+
try {
10+
constant('Foo::C1');
11+
} catch (ValueError $exception) {
12+
echo $exception->getMessage() . "\n";
13+
}
1014
--EXPECTF--
11-
Warning: constant(): Couldn't find constant Foo::C1 in %s on line %d
12-
NULL
15+
Couldn't find constant Foo::C1

0 commit comments

Comments
 (0)