Skip to content

Commit

Permalink
Enforce __set_state() parameter type
Browse files Browse the repository at this point in the history
This fixes one of the issues reported in bug #79925. The parameter
type check for this particular method was missed.
  • Loading branch information
nikic committed Aug 3, 2020
1 parent a4c015b commit 5d4659c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Zend/tests/magic_methods_020.phpt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

3 comments on commit 5d4659c

@ondrejmirtes
Copy link
Contributor

Choose a reason for hiding this comment

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

@nikic Does it also allow contravariance with mixed $properties?

@ondrejmirtes
Copy link
Contributor

Choose a reason for hiding this comment

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

@nikic Also, thank you! You're awesome! 🔥

@nikic
Copy link
Member Author

@nikic nikic commented on 5d4659c Aug 3, 2020

Choose a reason for hiding this comment

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

@nikic Does it also allow contravariance with mixed $properties?

Yeah, contravariance is already allowed there (and tested for some other methods).

Please sign in to comment.