it might be a newbie question, but does this PHP 5.4 feature
“Added class member access on instantiation (e.g. (new foo)->bar()) support.”
means that Class::factory('some_class_name') will be gone?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not necessarily. A factory usually does a few things; first, it decides which kind of object to return based on some conditions, second, it generally handles dependencies too. That’s to say that if A needs B, you request A from the factory, and B will be passed along to it in creation.
You can’t do that with the
(new Foo)->bar().What’s more, is that the factory will return an object, which you can do dynamically now anyway:
Having a syntax like
($foo = new Foo)->bar()is helpful for the situations where you want to execute a method right after creation, or if you’re only ever executing one method on the object anyway.