|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79195 "callable" not a valid type hint for class properties.
Submitted: 2020-01-30 03:30 UTC Modified: 2020-01-30 04:43 UTC
From: a at b dot c dot de Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 7.4.2 OS: Windows 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: a at b dot c dot de
New email:
PHP Version: OS:


 [2020-01-30 03:30 UTC] a at b dot c dot de
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.


Test script:
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-30 04:43 UTC]
-Status: Open +Status: Not a bug
 [2020-01-30 04:43 UTC]
See the RFC for why callable is not supported.
 [2020-08-28 19:33 UTC] antonfedonyuk at gmail dot com
You can define "iterable" properties, but can't define "callable" properties. It's irrationally/illogically.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Feb 04 06:05:49 2023 UTC