-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Late Static Bindings in Wurst #977
Comments
Static functions are just regular functions that are put into the class namespace, there is no dispatch for them. Why would you wanna do this in first place, why not use a closure instead? |
If you want to reuse the test function for class A and B you could put it into a Wurst module. Another approach might be the Singleton pattern. I don't think it's worth it to add this as an additional feature to the language. |
I've updated the code with a member usage instead of a method, which is closer to what I want to achieve. |
Seems like a less readable and obvious way to override something - I still don't really see a benefit. |
In PHP, it's mainly used for Active Record-based models and Factory patterns. abstract class A
{
static function create()
{
return new static();
}
}
class B extends A
{
// Specific stuff
}
$obj = B::create(); // Instanciate B object |
Is your feature request related to a problem? Please describe.
Unless I'm missing something, it's not possible to access a child static member/method from the parent class.
Overriding may do the trick for methods but not for (static) attributes.
Describe the solution you'd like
In PHP (yes, again) you can use the static keyword to reference the child class name in the parent class :
I've no idea if it's possible in the current state/workflow of Wurst though.
The text was updated successfully, but these errors were encountered: