diff --git a/Library/FunctionLike/ReturnType/Collection.php b/Library/FunctionLike/ReturnType/Collection.php index 3508e7e161..aa21a1477c 100644 --- a/Library/FunctionLike/ReturnType/Collection.php +++ b/Library/FunctionLike/ReturnType/Collection.php @@ -44,7 +44,7 @@ public function attach($returnType, $definition = null) $wrong = \is_object($returnType) ? 'instance of '.\get_class($returnType) : \gettype($returnType); throw new InvalidArgumentException( - \sprintf('Expecting an instance of %s, got %s', TypeInterface::class, $wrong) + sprintf('Expecting an instance of %s, got %s', TypeInterface::class, $wrong) ); } diff --git a/unit-tests/fixtures/typehints/expected2.c b/unit-tests/fixtures/typehints/expected2.c index cf4e784ffd..33313fbb26 100644 --- a/unit-tests/fixtures/typehints/expected2.c +++ b/unit-tests/fixtures/typehints/expected2.c @@ -197,6 +197,7 @@ PHP_FUNCTION(f_TypeHints_retval_nullable_string); PHP_FUNCTION(f_TypeHints_retval_nullable_boolean); PHP_FUNCTION(f_TypeHints_retval_nullable_char); PHP_FUNCTION(f_TypeHints_retval_object_or_scalar); +PHP_FUNCTION(f_TypeHints_retval_array_of_objects); zend_function_entry php_typehints_functions[] = { ZEND_NS_NAMED_FE("TypeHints", args, ZEND_FN(f_TypeHints_args), arginfo_f_typehints_args) @@ -219,6 +220,7 @@ ZEND_NS_NAMED_FE("TypeHints", retval_nullable_string, ZEND_FN(f_TypeHints_retval ZEND_NS_NAMED_FE("TypeHints", retval_nullable_boolean, ZEND_FN(f_TypeHints_retval_nullable_boolean), NULL) ZEND_NS_NAMED_FE("TypeHints", retval_nullable_char, ZEND_FN(f_TypeHints_retval_nullable_char), NULL) ZEND_NS_NAMED_FE("TypeHints", retval_object_or_scalar, ZEND_FN(f_TypeHints_retval_object_or_scalar), NULL) +ZEND_NS_NAMED_FE("TypeHints", retval_array_of_objects, ZEND_FN(f_TypeHints_retval_array_of_objects), NULL) ZEND_FE_END }; diff --git a/unit-tests/fixtures/typehints/expected3.c b/unit-tests/fixtures/typehints/expected3.c index f172b0185a..75783240a3 100644 --- a/unit-tests/fixtures/typehints/expected3.c +++ b/unit-tests/fixtures/typehints/expected3.c @@ -300,6 +300,14 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_f_typehints_retval_nullable_char ZEND_END_ARG_INFO() PHP_FUNCTION(f_TypeHints_retval_object_or_scalar); +PHP_FUNCTION(f_TypeHints_retval_array_of_objects); +#if PHP_VERSION_ID >= 70200 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_f_typehints_retval_array_of_objects, 0, 0, IS_ARRAY, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_f_typehints_retval_array_of_objects, 0, 0, IS_ARRAY, NULL, 0) +#endif +ZEND_END_ARG_INFO() + zend_function_entry php_typehints_functions[] = { ZEND_NS_NAMED_FE("TypeHints", args, ZEND_FN(f_TypeHints_args), arginfo_f_typehints_args) @@ -322,6 +330,7 @@ ZEND_NS_NAMED_FE("TypeHints", retval_nullable_string, ZEND_FN(f_TypeHints_retval ZEND_NS_NAMED_FE("TypeHints", retval_nullable_boolean, ZEND_FN(f_TypeHints_retval_nullable_boolean), arginfo_f_typehints_retval_nullable_boolean) ZEND_NS_NAMED_FE("TypeHints", retval_nullable_char, ZEND_FN(f_TypeHints_retval_nullable_char), arginfo_f_typehints_retval_nullable_char) ZEND_NS_NAMED_FE("TypeHints", retval_object_or_scalar, ZEND_FN(f_TypeHints_retval_object_or_scalar), NULL) +ZEND_NS_NAMED_FE("TypeHints", retval_array_of_objects, ZEND_FN(f_TypeHints_retval_array_of_objects), arginfo_f_typehints_retval_array_of_objects) ZEND_FE_END }; diff --git a/unit-tests/fixtures/typehints/expected_retval2.h b/unit-tests/fixtures/typehints/expected_retval2.h index f489fbce36..57283beeeb 100644 --- a/unit-tests/fixtures/typehints/expected_retval2.h +++ b/unit-tests/fixtures/typehints/expected_retval2.h @@ -16,6 +16,7 @@ PHP_METHOD(TypeHints_RetVal, retval_int); PHP_METHOD(TypeHints_RetVal, retval_long); PHP_METHOD(TypeHints_RetVal, retval_double); PHP_METHOD(TypeHints_RetVal, retval_array); +PHP_METHOD(TypeHints_RetVal, retval_array_of_objects); PHP_METHOD(TypeHints_RetVal, retval_collection); PHP_METHOD(TypeHints_RetVal, retval_retval); PHP_METHOD(TypeHints_RetVal, retval_nullable_int); @@ -44,6 +45,7 @@ ZEPHIR_INIT_FUNCS(typehints_retval_method_entry) { PHP_ME(TypeHints_RetVal, retval_long, NULL, ZEND_ACC_PUBLIC) PHP_ME(TypeHints_RetVal, retval_double, NULL, ZEND_ACC_PUBLIC) PHP_ME(TypeHints_RetVal, retval_array, NULL, ZEND_ACC_PUBLIC) + PHP_ME(TypeHints_RetVal, retval_array_of_objects, NULL, ZEND_ACC_PUBLIC) PHP_ME(TypeHints_RetVal, retval_collection, NULL, ZEND_ACC_PUBLIC) PHP_ME(TypeHints_RetVal, retval_retval, NULL, ZEND_ACC_PUBLIC) PHP_ME(TypeHints_RetVal, retval_nullable_int, NULL, ZEND_ACC_PUBLIC) diff --git a/unit-tests/fixtures/typehints/expected_retval3.h b/unit-tests/fixtures/typehints/expected_retval3.h index 892fb290de..02a2a9d8d8 100644 --- a/unit-tests/fixtures/typehints/expected_retval3.h +++ b/unit-tests/fixtures/typehints/expected_retval3.h @@ -16,6 +16,7 @@ PHP_METHOD(TypeHints_RetVal, retval_int); PHP_METHOD(TypeHints_RetVal, retval_long); PHP_METHOD(TypeHints_RetVal, retval_double); PHP_METHOD(TypeHints_RetVal, retval_array); +PHP_METHOD(TypeHints_RetVal, retval_array_of_objects); PHP_METHOD(TypeHints_RetVal, retval_collection); PHP_METHOD(TypeHints_RetVal, retval_retval); PHP_METHOD(TypeHints_RetVal, retval_nullable_int); @@ -86,6 +87,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_array, 0 #endif ZEND_END_ARG_INFO() +#if PHP_VERSION_ID >= 70200 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_array_of_objects, 0, 0, IS_ARRAY, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_array_of_objects, 0, 0, IS_ARRAY, NULL, 0) +#endif +ZEND_END_ARG_INFO() + #if PHP_VERSION_ID >= 70200 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_collection, 0, 0, IS_ARRAY, 0) #else @@ -177,6 +185,7 @@ ZEPHIR_INIT_FUNCS(typehints_retval_method_entry) { PHP_ME(TypeHints_RetVal, retval_long, arginfo_typehints_retval_retval_long, ZEND_ACC_PUBLIC) PHP_ME(TypeHints_RetVal, retval_double, arginfo_typehints_retval_retval_double, ZEND_ACC_PUBLIC) PHP_ME(TypeHints_RetVal, retval_array, arginfo_typehints_retval_retval_array, ZEND_ACC_PUBLIC) + PHP_ME(TypeHints_RetVal, retval_array_of_objects, arginfo_typehints_retval_retval_array_of_objects, ZEND_ACC_PUBLIC) PHP_ME(TypeHints_RetVal, retval_collection, arginfo_typehints_retval_retval_collection, ZEND_ACC_PUBLIC) PHP_ME(TypeHints_RetVal, retval_retval, arginfo_typehints_retval_retval_retval, ZEND_ACC_PUBLIC) PHP_ME(TypeHints_RetVal, retval_nullable_int, arginfo_typehints_retval_retval_nullable_int, ZEND_ACC_PUBLIC) diff --git a/unit-tests/fixtures/typehints/typehints/retval.zep b/unit-tests/fixtures/typehints/typehints/retval.zep index 4d5976202a..3c5b484162 100644 --- a/unit-tests/fixtures/typehints/typehints/retval.zep +++ b/unit-tests/fixtures/typehints/typehints/retval.zep @@ -75,6 +75,11 @@ class RetVal { return []; } + /** @link https://github.com/phalcon/zephir/issues/1779 */ + public function retval_array_of_objects() -> <\stdClass[]> { + return []; + } + public function retval_collection() -> { return []; } @@ -213,3 +218,8 @@ function retval_nullable_char() -> char | null { function retval_object_or_scalar() -> <\stdClass> | bool { return false; } + +/** @link https://github.com/phalcon/zephir/issues/1779 */ +function retval_array_of_objects() -> <\stdClass[]> { + return []; +}