How to implement this program I want to create two methods in a class, such as PHPcodeclassren {publicfunctionlisting () {// code} publicfunctionlisting ($ dd) how can this program be implemented?
I want to create two methods in a class, such
PHP code
class ren{public function listing(){//code}public function listing($dd){//code}}
Can this work? Or is there a better way?
------ Solution --------------------
Only one function or method name can be defined in PHP. Only detours can be taken
Class ren
{
Private function _ listing ()
{
// Code
}
Public function listing ($ dd = null)
{
Is_null ($ dd) & $ this-> _ listing ();
// Code
}
}
(New ren ()-> listing ();
------ Solution --------------------
Function method overload?
Sorry, php does not support it!
Php is just a dynamic web page. it is not as complicated as it is.
If php is the same as C ++ and Java, I don't think it will be available.
However, php provides
Func_get_arg
Func_num_args
Func_get_args
Three functions. It can completely solve your problem, but you need to implement it by yourself.
------ Solution --------------------
Php does not support overloading.
In fact, many advanced languages do not support overloading. c ++ only uses a strange method (compiler-level) for overloading. it is generally considered that overloading will lead to confusion in program reading.