Re: [RFC] Callable constructors
| From: | Stanislav Malyshev | Date: | Wed, 02 Mar 2016 06:19:38 +0000 |
| Subject: | Re: [RFC] Callable constructors | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-91472@lists.php.net to get a copy of this message | ||
Hi!
> If constructors had always been callable in PHP, this would be a
> standard thing to do and not controversial imo. It's only due to
> reasons lost in the mists of time, that object instantiation can only
> be invoked via 'new' that it's not possible currently, and so needs an
> RFC to change.
Constructors have always been callable in PHP and still are. They are
functions like any other. What you need is a factory method, not a
constructor - constructor is called to initialize object, not create it.
But you can create factory methods at will, you just don't have to call
it __construct.
--
Stas Malyshev
smalyshev@gmail.com