Bug #79195 [NEW]: "callable" not a valid type hint for class properties.
| From: | a at b dot c dot de | Date: | Thu, 30 Jan 2020 03:30:07 +0000 |
| Subject: | Bug #79195 [NEW]: "callable" not a valid type hint for class properties. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-225238@lists.php.net to get a copy of this message | ||
From: a at b dot c dot de
Operating system: Windows 10
PHP version: 7.4.2
Package: Class/Object related
Bug Type: Bug
Bug description:"callable" not a valid type hint for class properties.
Description:
------------
Of the list of available type declarations[1], callable is unique in
that class properties cannot be declared as such.
"Closure" can be used, but of course that prevents callables of other
types (strings and arrays) from being stored.
This may be a WONTFIX and a corresponding comment in the documentation
saying "you can't do that", but since the more general "callable" type
declaration exists and can and is used elsewhere, there seems a priori
no reason why it can't be used as a property.
[1]
https://www.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
Test script:
---------------
<?php
class Testing
{
private callable $foo;
public function __construct($foo = null)
{
$this->foo = $foo;
}
}
new Testing(fn($a) => $a);
Expected result:
----------------
Nothing; script tests compilation only.
Actual result:
--------------
PHP Fatal error: Property Testing::$foo cannot have type callable in
C:\tmp\test.php on line 4
--
Edit bug report at https://bugs.php.net/bug.php?id=79195&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79195&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79195&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79195&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79195&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79195&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79195&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79195&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79195&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79195&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79195&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79195&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79195&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79195&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79195&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79195&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79195&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79195&r=mysqlcfg