note 129516 added to functions.anonymous
| From: | HayleyWatson | Date: | Tue, 21 May 2024 04:43:01 +0000 |
| Subject: | note 129516 added to functions.anonymous | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221334@lists.php.net to get a copy of this message | ||
If you have a closure (or other callable) stored in an object property and you want to call it, you
can use parentheses to disambiguate between it and a method call:
<?php
class Test
{
public $callable;
function __construct()
{
$this->callable = function($a) { return $a + 2; };
}
}
$t = new Test;
echo ($t->callable)(40);
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.131 (proxied: 222.152.65.7)
----
Manual Page -- https://php.net/manual/en/functions.anonymous.php
Edit -- https://main.php.net/note/edit/129516
Del: integrated -- https://main.php.net/note/delete/129516/integrated
Del: useless -- https://main.php.net/note/delete/129516/useless
Del: bad code -- https://main.php.net/note/delete/129516/bad+code
Del: spam -- https://main.php.net/note/delete/129516/spam
Del: non-english -- https://main.php.net/note/delete/129516/non-english
Del: in docs -- https://main.php.net/note/delete/129516/in+docs
Del: other reasons-- https://main.php.net/note/delete/129516
Reject -- https://main.php.net/note/reject/129516
Search -- https://main.php.net/manage/user-notes.php