From 557061507e580a03444fd2b04fa060817eb91695 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 13 Jan 2021 10:43:54 +0100 Subject: [PATCH 1/2] Fix anonymous class union typehints --- Zend/zend_compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index c82a82fc9a9f3..f55f116dd458b 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1154,7 +1154,7 @@ static zend_string *add_type_string(zend_string *type, zend_string *new_type) { } result = zend_string_concat3( - ZSTR_VAL(type), ZSTR_LEN(type), "|", 1, ZSTR_VAL(new_type), ZSTR_LEN(new_type)); + ZSTR_VAL(type), strlen(ZSTR_VAL(type)), "|", 1, ZSTR_VAL(new_type), strlen(ZSTR_VAL(new_type))); zend_string_release(type); return result; } From 2a96ba5353ef53c1a5fe654272ddff24112881f5 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 13 Jan 2021 17:00:15 +0100 Subject: [PATCH 2/2] Add unit test --- .../union_types/anonymous_class.phpt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Zend/tests/type_declarations/union_types/anonymous_class.phpt diff --git a/Zend/tests/type_declarations/union_types/anonymous_class.phpt b/Zend/tests/type_declarations/union_types/anonymous_class.phpt new file mode 100644 index 0000000000000..1e009f22b00f0 --- /dev/null +++ b/Zend/tests/type_declarations/union_types/anonymous_class.phpt @@ -0,0 +1,30 @@ +--TEST-- +Union with anonymous class type +--FILE-- +testParam(null); +} catch (\Throwable $e) { + echo $e->getMessage()."\n"; +} + +try { + $a->test(); +} catch (\Throwable $e) { + echo $e->getMessage()."\n"; +} +?> +--EXPECTF-- +class@anonymous(): Argument #1 ($a) must be of type class@anonymous|string, null given, called in %s on line %d +class@anonymous::test(): Return value must be of type class@anonymous|string, stdClass returned