com php-src: Fixed bug #72920 (Accessing a private constant using constant() creates an exception AND warning): NEWS ext/standard /basic_functions.c
ext/standard/tests/general_functions /bug72920.phpt
| From: | Xinchen Hui | Date: | Mon, 22 Aug 2016 15:44:38 +0000 |
| Subject: | com php-src: Fixed bug #72920 (Accessing a private constant using constant() creates an exception AND warning): NEWS ext/standard /basic_functions.c ext/standard/tests/general_functions /bug72920.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94043@lists.php.net to get a copy of this message | ||
Commit: 434ae90e852ed2b39432baf30d928e26b834c03e
Author: Xinchen Hui <laruence@gmail.com> Mon, 22 Aug 2016 23:44:38 +0800
Parents: caf890b29166c8a1c921b7f9d9fa4e6eec02c0dd
Branches: PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=434ae90e852ed2b39432baf30d928e26b834c03e
Log:
Fixed bug #72920 (Accessing a private constant using constant() creates an exception AND warning)
Bugs:
https://bugs.php.net/72920
Changed paths:
M NEWS
M ext/standard/basic_functions.c
A ext/standard/tests/general_functions/bug72920.phpt
Diff:
diff --git a/NEWS b/NEWS
index d3e6e9f..31eded8 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,10 @@ PHP NEWS
. Reverted prepending \ for class names and ? for nullable types returned
from ReflectionType::__toString(). (Trowski)
+- Standard:
+ . Fixed bug #72920 (Accessing a private constant using constant() creates
+ an exception AND warning). (Laruence)
+
- XML:
. Fixed bug #72714 (_xml_startElementHandler() segmentation fault). (cmb)
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 5463665..58f9b49 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -3887,7 +3887,9 @@ PHP_FUNCTION(constant)
}
}
} else {
- php_error_docref(NULL, E_WARNING, "Couldn't find constant %s",
ZSTR_VAL(const_name));
+ if (!EG(exception)) {
+ php_error_docref(NULL, E_WARNING, "Couldn't find constant %s",
ZSTR_VAL(const_name));
+ }
RETURN_NULL();
}
}
diff --git a/ext/standard/tests/general_functions/bug72920.phpt
b/ext/standard/tests/general_functions/bug72920.phpt
new file mode 100644
index 0000000..b5ca476
--- /dev/null
+++ b/ext/standard/tests/general_functions/bug72920.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #72920 (Accessing a private constant using constant() creates an exception AND warning)
+--FILE--
+<?php
+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"