]> granicus.if.org Git - php/commitdiff
Enforce __set_state() parameter type
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 3 Aug 2020 08:23:06 +0000 (10:23 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 3 Aug 2020 08:23:06 +0000 (10:23 +0200)
This fixes one of the issues reported in bug #79925. The parameter
type check for this particular method was missed.

Zend/tests/magic_methods_020.phpt [new file with mode: 0644]
Zend/zend_API.c

diff --git a/Zend/tests/magic_methods_020.phpt b/Zend/tests/magic_methods_020.phpt
new file mode 100644 (file)
index 0000000..45e144c
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+__set_state first parameter must be an array
+--FILE--
+<?php
+
+class Foo {
+       public static function __set_state(int $properties) {}
+}
+
+?>
+--EXPECTF--
+Fatal error: Foo::__set_state(): Parameter #1 ($properties) must be of type array when declared in %s on line %d
index 1b00e51416a32631066cad5df7e690991fa5c306..c2f887a5bcc6c1e8eea494f1da29c4ebec0cb6b4 100644 (file)
@@ -2187,6 +2187,7 @@ ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce,
                zend_check_magic_method_args(1, ce, fptr, error_type);
                zend_check_magic_method_static(ce, fptr, error_type);
                zend_check_magic_method_public(ce, fptr, error_type);
+               zend_check_magic_method_arg_type(0, ce, fptr, error_type, MAY_BE_ARRAY);
                zend_check_magic_method_return_type(ce, fptr, error_type, MAY_BE_OBJECT);
        } else if (zend_string_equals_literal(lcname, "__invoke")) {
                zend_check_magic_method_non_static(ce, fptr, error_type);