Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Zend/tests/magic_methods_set_state_args.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
__set_state first argument must be an array
--FILE--
<?php
class Foo {
public function __set_state(string $name) {}
}
?>
--EXPECTF--
Fatal error: Type of first argument of Foo::__set_state() must be array in %s on line %d
8 changes: 8 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,14 @@ ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce,
&& fptr->common.num_args != 1
) {
zend_error(error_type, "Method %s::__unserialize() must take exactly 1 argument", ZSTR_VAL(ce->name));
} else if (
name_len == sizeof("__set_state") - 1
&& !memcmp(lcname, "__set_state", sizeof("__set_state") - 1)
&& fptr->common.num_args == 1
&& ZEND_TYPE_IS_SET(fptr->common.arg_info[0].type)
&& ZEND_TYPE_FULL_MASK(fptr->common.arg_info[1].type) != MAY_BE_ARRAY
) {
zend_error(error_type, "Type of first argument of %s::__set_state() must be array", ZSTR_VAL(ce->name));

@kocsismate kocsismate Apr 26, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use the %s::__set_state(): Argument #1 ($%s) must be of type array, %s given form?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll adopt it in #4177, thanks!

}
}
/* }}} */
Expand Down