KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to create an instance of a class and call a method on that instance, in a single line of code. PHP won't allow calling a method on a regular constructor: new Foo()->set_sth(); // Outputs an error. So I'm using, if I can call it that, a static constructor: Foo::construct()->set_sth(); Here's my question: Is using static constructors like that considered a good practice and if yes, how would you recommend naming the methods for these static constructors? I've been hesitating over the following options: Foo::construct(); Foo::create(); Foo::factory() Foo::Foo(); constructor::Foo();
Tags (comma-separated)
Save Edits
Cancel