summaryrefslogtreecommitdiff
path: root/Zend/zend_exceptions.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-05-28 12:23:37 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-05-28 13:55:38 +0200
commitaaae77f7f113d4a0a684e2615ef798703ccd089e (patch)
tree91e38963114c5394d2423ba5de23f5d9aa0e3084 /Zend/zend_exceptions.c
parentc16dbed0c4ef031d7ee0cd86bd3fd88f594b5030 (diff)
downloadphp-git-aaae77f7f113d4a0a684e2615ef798703ccd089e.tar.gz
Make Exception::$trace typed array property
This is a private property, so we are allowed to add a type. The new declaration of the property is: private array $trace = []; This ensures that Exception::getTrace() does indeed return an array. Userland code that was modifying the property through refleciton may have to be adjusted to assign an array (instead of null, for example). Closes GH-5636.
Diffstat (limited to 'Zend/zend_exceptions.c')
-rw-r--r--Zend/zend_exceptions.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c
index 06c1c9897c..21775a26ca 100644
--- a/Zend/zend_exceptions.c
+++ b/Zend/zend_exceptions.c
@@ -606,10 +606,12 @@ ZEND_METHOD(Exception, getTraceAsString)
base_ce = i_get_exception_base(object);
trace = zend_read_property_ex(base_ce, object, ZSTR_KNOWN(ZEND_STR_TRACE), 1, &rv);
- if (Z_TYPE_P(trace) != IS_ARRAY) {
- zend_type_error("Trace is not an array");
- return;
+ if (EG(exception)) {
+ RETURN_THROWS();
}
+
+ /* Type should be guaranteed by property type. */
+ ZEND_ASSERT(Z_TYPE_P(trace) == IS_ARRAY);
ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(trace), index, frame) {
if (Z_TYPE_P(frame) != IS_ARRAY) {
zend_error(E_WARNING, "Expected array for frame " ZEND_ULONG_FMT, index);
@@ -736,12 +738,19 @@ ZEND_METHOD(Exception, __toString)
static void declare_exception_properties(zend_class_entry *ce)
{
+ zval val;
+
zend_declare_property_string(ce, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED);
zend_declare_property_string(ce, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE);
zend_declare_property_long(ce, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED);
zend_declare_property_null(ce, "file", sizeof("file")-1, ZEND_ACC_PROTECTED);
zend_declare_property_null(ce, "line", sizeof("line")-1, ZEND_ACC_PROTECTED);
- zend_declare_property_null(ce, "trace", sizeof("trace")-1, ZEND_ACC_PRIVATE);
+
+ ZVAL_EMPTY_ARRAY(&val);
+ zend_declare_typed_property(
+ ce, ZSTR_KNOWN(ZEND_STR_TRACE), &val, ZEND_ACC_PRIVATE, NULL,
+ (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY));
+
zend_declare_property_null(ce, "previous", sizeof("previous")-1, ZEND_ACC_PRIVATE);
}