How to implement this program

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.