Skip to content

Commit 86379b6

Browse files
committed
Warn if return type on internal __toString() is missing
1 parent 85acad5 commit 86379b6

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

Zend/zend_API.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,8 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend
27162716
* interface. */
27172717
if (scope && zend_string_equals_literal_ci(internal_function->function_name, "__tostring") &&
27182718
!(internal_function->fn_flags & ZEND_ACC_HAS_RETURN_TYPE)) {
2719+
zend_error(E_CORE_WARNING, "%s::__toString() implemented without string return type",
2720+
ZSTR_VAL(scope->name));
27192721
internal_function->arg_info = (zend_internal_arg_info *) arg_info_toString + 1;
27202722
internal_function->fn_flags |= ZEND_ACC_HAS_RETURN_TYPE;
27212723
internal_function->num_args = internal_function->required_num_args = 0;

ext/zend_test/test.stub.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ class _ZendTestClass implements _ZendTestInterface {
2121

2222
public static function is_object(): int {}
2323

24-
/**
25-
* @deprecated
26-
* @return string
27-
*/
28-
public function __toString() {}
24+
/** @deprecated */
25+
public function __toString(): string {}
2926

3027
public function returnsStatic(): static {}
3128

ext/zend_test/test_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: d0ffefd20355db472f4a8adc018bec959e670bb3 */
2+
* Stub hash: 7326163f8ce5340c12e74af72d47a8926eb39786 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -77,7 +77,7 @@ ZEND_END_ARG_INFO()
7777
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestClass_is_object, 0, 0, IS_LONG, 0)
7878
ZEND_END_ARG_INFO()
7979

80-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class__ZendTestClass___toString, 0, 0, 0)
80+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestClass___toString, 0, 0, IS_STRING, 0)
8181
ZEND_END_ARG_INFO()
8282

8383
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestClass_returnsStatic, 0, 0, IS_STATIC, 0)

0 commit comments

Comments
 (0)