Reputation: 299
I want to overload two methods in a model of Yii framework.
Here, I want to say that like in Java we have method overloading concept means method has same name but differs in number of parameters pass to that method. So these similar concept can apply in PHP Yii framework's model class. In Yii model class, I want to create two methods like,
public function test(){
//method logic
}
public function test(int parameters){
//method logic
}
Is it possible to create like these? I am getting error like "cannot define same function".
Upvotes: 2
Views: 1059
Reputation: 388
What you are talking about is not supported in PHP. You could try using default values in function arguments. For eg.
function foo($int_param = 0) // do something
You could also use func_get_args. You define your function to not accept parameters and then get the arguments using func_get_args().
These approaches are suitable if there is not a lot of difference between the functions that you're trying to implement.
Upvotes: 3