Skip to content

Commit aaebf3b

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
2 parents dbd7fba + 5297bed commit aaebf3b

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

Zend/zend_constants.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
378378
ret_constant = NULL;
379379
} else {
380380
if (!zend_verify_const_access(c, scope)) {
381-
zend_throw_error(NULL, "Cannot access %s const %s::%s", zend_visibility_string(Z_ACCESS_FLAGS(c->value)), ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
381+
if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
382+
zend_throw_error(NULL, "Cannot access %s const %s::%s", zend_visibility_string(Z_ACCESS_FLAGS(c->value)), ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
383+
}
382384
goto failure;
383385
}
384386
ret_constant = &c->value;

ext/standard/tests/general_functions/bug72920.phpt

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ class Foo {
66
private const C1 = "a";
77
}
88

9-
try {
10-
var_dump(constant('Foo::C1'));
11-
} catch (Error $e) {
12-
var_dump($e->getMessage());
13-
}
14-
--EXPECT--
15-
string(35) "Cannot access private const Foo::C1"
9+
var_dump(constant('Foo::C1'));
10+
--EXPECTF--
11+
Warning: constant(): Couldn't find constant Foo::C1 in %s on line %d
12+
NULL

tests/classes/constants_visibility_002.phpt

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,4 @@ constant('A::protectedConst');
2121
string(14) "protectedConst"
2222
string(14) "protectedConst"
2323

24-
Fatal error: Uncaught Error: Cannot access protected const A::protectedConst in %s:14
25-
Stack trace:
26-
#0 %s(14): constant('A::protectedCon...')
27-
#1 {main}
28-
thrown in %s on line 14
24+
Warning: constant(): Couldn't find constant A::protectedConst in %s on line %d

tests/classes/constants_visibility_003.phpt

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,4 @@ constant('A::privateConst');
2121
string(12) "privateConst"
2222
string(12) "privateConst"
2323

24-
Fatal error: Uncaught Error: Cannot access private const A::privateConst in %s:14
25-
Stack trace:
26-
#0 %s(14): constant('A::privateConst')
27-
#1 {main}
28-
thrown in %s on line 14
24+
Warning: constant(): Couldn't find constant A::privateConst in %s on line %d
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Defined on private constant should not raise exception
3+
--FILE--
4+
<?php
5+
6+
class Foo
7+
{
8+
private const BAR = 1;
9+
}
10+
echo (int)defined('Foo::BAR');
11+
--EXPECTF--
12+
0

0 commit comments

Comments
 (0)