Re: [RFC] Object Initializer
| From: | Arnold Daniels | Date: | Mon, 16 Sep 2019 07:41:40 +0000 |
| Subject: | Re: [RFC] Object Initializer | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107142@lists.php.net to get a copy of this message | ||
Features like
func_get_args(ARGS_OBJECT) and hoist aren't really
needed. You can use get_defined_vars() instead.
Many of my classes have constructors like;
public function __construct(int $foo, string $bar, bool $flag = false)
{
set_object_vars($this, get_defined_vars());
}
FYI set_object_vars is a user-space function that does the reverse of
get_object_vars. You could use a foreach loop instead.
----
However when a class for a data object has 20 properties, I don't really want to put all 20 as
constructor arguments. The object initialize RFC be the preferred solution for me in that case, even
if named parameters was also supported. As such, I don't think the two features are mutually
exclusive.
[Arnold Daniels - Chat @
Spike](https://www.spikenow.com/?ref=spike-organic-signature&_ts=5w9qi) [5w9qi]
On September 16, 2019 at 6:22 GMT, Michał Brzuchalski <michal.brzuchalski@gmail.com> wrote: