--FILE--
<?php
-var_dump(constant(""));
+try {
+ var_dump(constant(""));
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
define("TEST_CONST", 1);
var_dump(constant("TEST_CONST"));
echo "Done\n";
?>
---EXPECTF--
-Warning: constant(): Couldn't find constant in %s on line %d
-NULL
+--EXPECT--
+Undefined constant ''
int(1)
string(4) "test"
Done
class A {
const B = 1;
}
-var_dump(constant('A::B1'));
+try {
+ constant('A::B1');
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
?>
---EXPECTF--
-Warning: constant(): Couldn't find constant A::B1 in %s on line %d
-NULL
+--EXPECT--
+Undefined class constant 'A::B1'
ZEND_PARSE_PARAMETERS_END();
scope = zend_get_executed_scope();
- c = zend_get_constant_ex(const_name, scope, ZEND_FETCH_CLASS_SILENT);
- if (c) {
- ZVAL_COPY_OR_DUP(return_value, c);
- if (Z_TYPE_P(return_value) == IS_CONSTANT_AST) {
- if (UNEXPECTED(zval_update_constant_ex(return_value, scope) != SUCCESS)) {
- return;
- }
- }
- } else {
- if (!EG(exception)) {
- php_error_docref(NULL, E_WARNING, "Couldn't find constant %s", ZSTR_VAL(const_name));
+ c = zend_get_constant_ex(const_name, scope, 0);
+ if (!c) {
+ RETURN_THROWS();
+ }
+
+ ZVAL_COPY_OR_DUP(return_value, c);
+ if (Z_TYPE_P(return_value) == IS_CONSTANT_AST) {
+ if (UNEXPECTED(zval_update_constant_ex(return_value, scope) != SUCCESS)) {
+ RETURN_THROWS();
}
- RETURN_NULL();
}
}
/* }}} */
private const C1 = "a";
}
-var_dump(constant('Foo::C1'));
---EXPECTF--
-Warning: constant(): Couldn't find constant Foo::C1 in %s on line %d
-NULL
+try {
+ var_dump(constant('Foo::C1'));
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+?>
+--EXPECT--
+Cannot access private const Foo::C1
A::staticConstDump();
(new A())->constDump();
-constant('A::protectedConst');
+try {
+ constant('A::protectedConst');
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
?>
---EXPECTF--
+--EXPECT--
string(14) "protectedConst"
string(14) "protectedConst"
-
-Warning: constant(): Couldn't find constant A::protectedConst in %s on line %d
+Cannot access protected const A::protectedConst
A::staticConstDump();
(new A())->constDump();
-constant('A::privateConst');
+try {
+ constant('A::privateConst');
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
?>
---EXPECTF--
+--EXPECT--
string(12) "privateConst"
string(12) "privateConst"
-
-Warning: constant(): Couldn't find constant A::privateConst in %s on line %d
+Cannot access private const A::privateConst
--FILE--
<?php
define('::', true);
-var_dump(constant('::'));
+try {
+ var_dump(constant('::'));
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
?>
--EXPECTF--
Warning: Class constants cannot be defined or redefined in %s on line %d
-Warning: constant(): Couldn't find constant :: in %s on line %d
-NULL
+Fatal error: Class '' not found in %s on line %d