-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed as not planned
Labels
Description
Description
The following code:
<?php
class Test {
public private(set) \Closure $action {
set (callable $value) {
if (!$value instanceof \Closure) {
$value = $value(...);
}
$this->action = $value;
}
}
}
Resulted in this output:
Fatal error: Type of parameter $value of hook Test::$action::set must be compatible with property type
But I expected this output instead:
I expected no error.
As far as I am aware, callable
includes \Closure
. You can pass a Closure
to a callable
. So I would expect this to work. However, it gets rejected. Specifying set(\Closure|callable) { ... }
is a workaround.
It seems like either the variance detection is buggy or the definition of callable is wonkier than I thought.
PHP Version
PHP 8.4.8 (cli) (built: Jun 9 2025 13:49:53) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.8, Copyright (c) Zend Technologies
with Zend OPcache v8.4.8, Copyright (c), by Zend Technologies
with Xdebug v3.4.0, Copyright (c) 2002-2024, by Derick Rethans
(Though 3v4l confirms this error on all 8.4 releases.)
Operating System
No response