|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
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-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 12:01:32 2024 UTC