note 124026 added to language.oop5.anonymous
| From: | joey@php.net | Date: | Tue, 09 Jul 2019 16:54:14 +0000 |
| Subject: | note 124026 added to language.oop5.anonymous | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-211541@lists.php.net to get a copy of this message | ||
The only way to type hint this would appear to be as object.
If you need multiple instances of an anonymous class in a function you can use:
$class = function(string $arg):object {
return new class($arg) {
public function __construct(string $arg) {
$this->ow = $arg;
}
};
};
Though for the sake of structure it's ill advised to do something like this outside of a single
scope or that's used across multiple files. If you class is only used in one scope however then
it's probably not a code mess problem.
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.195 (proxied: 89.197.178.10)
----
Manual Page -- http://php.net/manual/en/language.oop5.anonymous.php
Edit -- https://master.php.net/note/edit/124026
Del: integrated -- https://master.php.net/note/delete/124026/integrated
Del: useless -- https://master.php.net/note/delete/124026/useless
Del: bad code -- https://master.php.net/note/delete/124026/bad+code
Del: spam -- https://master.php.net/note/delete/124026/spam
Del: non-english -- https://master.php.net/note/delete/124026/non-english
Del: in docs -- https://master.php.net/note/delete/124026/in+docs
Del: other reasons-- https://master.php.net/note/delete/124026
Reject -- https://master.php.net/note/reject/124026
Search -- https://master.php.net/manage/user-notes.php