Answer the question
In order to leave comments, you need to log in
Method overloading in PHP as in Java. Maybe?
In java, there is such a thing as method overloading. This means that we can write several methods with the same name, which will differ in the number or type of incoming data.
For example:
String getName(String fullname) {};
String getName(int id) {};
String getName(User user) {};
String getName(String firstName, String lastName) {};
Declaration of Framework\Widget\Icon::get() should be compatible with Framework\Base\Widget::get()
class A {
public function message ($user, $message) {}
}
class A extends B {
public function message ($user_id, $message, $type) {}
}
Answer the question
In order to leave comments, you need to log in
No, you can’t, although such wishes, as far as I remember, were in the RFC. Perhaps it will appear in the future.
Let's start with the fact that there is no strong typing in puff, and there is no out-of-the-box method reloading. Crutches and bicycles - that's my answer)
BUT if the functionality is the same as you wrote in the last lines - make the parameters optional
public function message ($user_id, $message="", $type="someDefaultType") {}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question