File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
tests/type_declarations/callable Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -10,5 +10,6 @@ class B extends A {
10
10
public function foo (callable $ c ): Closure {}
11
11
}
12
12
?>
13
- --EXPECTF--
14
- Fatal error: Declaration of B::foo(callable $c): Closure must be compatible with A::foo(Closure $c): callable in %s on line %d
13
+ OK
14
+ --EXPECT--
15
+ OK
Original file line number Diff line number Diff line change 23
23
#include "zend_execute.h"
24
24
#include "zend_inheritance.h"
25
25
#include "zend_interfaces.h"
26
+ #include "zend_closures.h"
26
27
#include "zend_smart_str.h"
27
28
#include "zend_operators.h"
28
29
#include "zend_exceptions.h"
@@ -478,6 +479,19 @@ static inheritance_status zend_is_class_subtype_of_type(
478
479
}
479
480
}
480
481
482
+ /* If the parent has 'callable' as a return type, then Closure satisfies the co-variant check */
483
+ if (ZEND_TYPE_FULL_MASK (proto_type ) & MAY_BE_CALLABLE ) {
484
+ if (!fe_ce ) fe_ce = lookup_class (fe_scope , fe_class_name );
485
+ if (!fe_ce ) {
486
+ have_unresolved = 1 ;
487
+ } else if (fe_ce == zend_ce_closure ) {
488
+ track_class_dependency (fe_ce , fe_class_name );
489
+ return INHERITANCE_SUCCESS ;
490
+ } else {
491
+ return INHERITANCE_ERROR ;
492
+ }
493
+ }
494
+
481
495
zend_type * single_type ;
482
496
483
497
/* Traverse the list of parent types and check if the current child (FE)
You can’t perform that action at this time.
0 commit comments