Skip to content

Commit 8efff2f

Browse files
committed
Fixed variance in param being contrvariant
1 parent e4f97be commit 8efff2f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Zend/tests/object_types/variance_in_param.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Bar extends Foo {
1515
var_dump(new Bar);
1616
?>
1717
--EXPECTF--
18+
Warning: Declaration of Bar::qux(Qux $qux) should be compatible with Foo::qux(object $object) in %s on line 10
1819
object(Bar)#%d (0) {
1920
}
2021

Zend/tests/object_types/variance_in_param_error.phpt renamed to Zend/tests/object_types/variance_in_param_contravariance.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Variance of object parameter type (fail)
2+
Variance of object parameter type
33
--FILE--
44
<?php
55
class Foo {
@@ -15,7 +15,6 @@ class Bar extends Foo {
1515
var_dump(new Bar);
1616
?>
1717
--EXPECTF--
18-
Warning: Declaration of Bar::qux(object $qux) should be compatible with Foo::qux(Qux $object) in %s on line 10
1918
object(Bar)#%d (0) {
2019
}
2120

Zend/zend_inheritance.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ static zend_always_inline zend_bool zend_iterable_compatibility_check(zend_arg_i
183183

184184
static int zend_do_perform_type_hint_check(const zend_function *fe, zend_arg_info *fe_arg_info, const zend_function *proto, zend_arg_info *proto_arg_info) /* {{{ */
185185
{
186-
if (ZEND_TRUTH(fe_arg_info->class_name) == 0 && ZEND_TRUTH(proto_arg_info->class_name)) {
186+
if (ZEND_LOG_XOR(fe_arg_info->class_name, proto_arg_info->class_name)) {
187187
/* Only one has a type declaration and the other one doesn't */
188188
return 0;
189189
}
190190

191-
if (fe_arg_info->class_name && proto_arg_info->class_name) {
191+
if (fe_arg_info->class_name) {
192192
zend_string *fe_class_name, *proto_class_name;
193193
const char *class_name;
194194

@@ -336,6 +336,10 @@ static zend_bool zend_do_perform_implementation_check(const zend_function *fe, c
336336
return 0;
337337
}
338338
break;
339+
340+
case IS_OBJECT: {
341+
return !fe_arg_info->class_name && proto_arg_info->class_name;
342+
} break;
339343

340344
default:
341345
return 0;
@@ -369,6 +373,10 @@ static zend_bool zend_do_perform_implementation_check(const zend_function *fe, c
369373
return 0;
370374
}
371375
break;
376+
377+
case IS_OBJECT: {
378+
return !proto->common.arg_info[-1].class_name && fe->common.arg_info[-1].class_name;
379+
} break;
372380

373381
default:
374382
return 0;

0 commit comments

Comments
 (0)