Php Basics ~

Source: Internet
Author: User
Basic php help ~~~~ Is there a question about inheritance and interfaces ?~~~~~~~ I have a classpersonimplementsispeak {publicfunctionspeak () {echo & quot; people speak & quot ;;}} class, birds classbirdimpl php Basics for help ~~~~
Is there a question about inheritance and interfaces ?~~~~~~~

I have a class person implements ispeak {public function speak () {echo "speaker" ;}} class,
Bird class bird implements ispeak {public function speak () {echo "" ;}} class
Interface ispeak {public function speak ();}

One artist yrPerson extends person {}
Because artists can learn birds and call me now. I want artists to call birds but do not repeat the code public function speak () {echo "";}


Give me a lecture !!!! The manager said that the code repetition rate is too high ~~~~~


------ Solution --------------------
Forget to inherit the person class. just change it.
PHP code
Class yrPerson extends person {// method for adding a speaker... public function show ($ a) {$ func = Factory: func ($ a); return $ func-> speak () ;}}$ person = new yrPerson (); $ person-> speak (); // speak by yourself $ person-> show ('dog'); // name a dog $ person-> show ('bird '); // learn birds // learn more...

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.