diff options
author | DanielCiochiu <daniel@ciochiu.ro> | 2019-02-12 11:40:46 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-02-12 11:42:33 +0100 |
commit | 07877c46e3057bc679766898d50529be812243f3 (patch) | |
tree | a1b80fb59cdec063ea890351ff01636acdb88454 | |
parent | 8e34de475699a4aa0fbc7b8430574b56dc839362 (diff) | |
download | php-git-07877c46e3057bc679766898d50529be812243f3.tar.gz |
Fixed bug #75546
By respecting the SILENT flag when checking the visibility of a
class constant.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | Zend/zend_constants.c | 4 | ||||
-rw-r--r-- | ext/standard/tests/general_functions/bug72920.phpt | 11 | ||||
-rw-r--r-- | tests/classes/constants_visibility_002.phpt | 6 | ||||
-rw-r--r-- | tests/classes/constants_visibility_003.phpt | 6 | ||||
-rw-r--r-- | tests/classes/constants_visibility_008.phpt | 12 |
6 files changed, 23 insertions, 18 deletions
@@ -5,6 +5,8 @@ PHP NEWS - Core: . Fixed bug #77589 (Core dump using parse_ini_string with numeric sections). (Laruence) + . Fixed bug #75546 (function "defined" should ignore class constant + visibility). (Daniel Ciochiu) - Exif: . Fixed bug #77564 (Memory leak in exif_process_IFD_TAG). (Ben Ramsey) diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c index 14d712235a..64265d3c19 100644 --- a/Zend/zend_constants.c +++ b/Zend/zend_constants.c @@ -341,7 +341,9 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope, ret_constant = NULL; } else { if (!zend_verify_const_access(c, scope)) { - 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)); + if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) { + 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)); + } goto failure; } ret_constant = &c->value; diff --git a/ext/standard/tests/general_functions/bug72920.phpt b/ext/standard/tests/general_functions/bug72920.phpt index b5ca4760c3..8ba4d26713 100644 --- a/ext/standard/tests/general_functions/bug72920.phpt +++ b/ext/standard/tests/general_functions/bug72920.phpt @@ -6,10 +6,7 @@ class Foo { private const C1 = "a"; } -try { - var_dump(constant('Foo::C1')); -} catch (Error $e) { - var_dump($e->getMessage()); -} ---EXPECT-- -string(35) "Cannot access private const Foo::C1" +var_dump(constant('Foo::C1')); +--EXPECTF-- +Warning: constant(): Couldn't find constant Foo::C1 in %s on line %d +NULL diff --git a/tests/classes/constants_visibility_002.phpt b/tests/classes/constants_visibility_002.phpt index 6ec9901269..4e0ecb1aa2 100644 --- a/tests/classes/constants_visibility_002.phpt +++ b/tests/classes/constants_visibility_002.phpt @@ -21,8 +21,4 @@ constant('A::protectedConst'); string(14) "protectedConst" string(14) "protectedConst" -Fatal error: Uncaught Error: Cannot access protected const A::protectedConst in %s:14 -Stack trace: -#0 %s(14): constant('A::protectedCon...') -#1 {main} - thrown in %s on line 14 +Warning: constant(): Couldn't find constant A::protectedConst in %s on line %d diff --git a/tests/classes/constants_visibility_003.phpt b/tests/classes/constants_visibility_003.phpt index 9c7bcfb21c..7c961695ed 100644 --- a/tests/classes/constants_visibility_003.phpt +++ b/tests/classes/constants_visibility_003.phpt @@ -21,8 +21,4 @@ constant('A::privateConst'); string(12) "privateConst" string(12) "privateConst" -Fatal error: Uncaught Error: Cannot access private const A::privateConst in %s:14 -Stack trace: -#0 %s(14): constant('A::privateConst') -#1 {main} - thrown in %s on line 14 +Warning: constant(): Couldn't find constant A::privateConst in %s on line %d diff --git a/tests/classes/constants_visibility_008.phpt b/tests/classes/constants_visibility_008.phpt new file mode 100644 index 0000000000..f24b70cf59 --- /dev/null +++ b/tests/classes/constants_visibility_008.phpt @@ -0,0 +1,12 @@ +--TEST-- +Defined on private constant should not raise exception +--FILE-- +<?php + +class Foo +{ + private const BAR = 1; +} +echo (int)defined('Foo::BAR'); +--EXPECTF-- +0 |