search
php基础~ Jun 13, 2016 pm 01:35 PM
functionpublicquot

php基础求助~~~~
有个问题是关于继承和接口的?~~~~~~~

我有个class person implements ispeak{public function speak(){echo "人说话";}}类,
鸟类class bird implements ispeak{public function speak(){echo "鸟叫";}}类 
 接口ispeak{public function speak();}

我一个艺人类 yrPerson extends person {} 
因为艺人可以学鸟叫 我现在想让艺人也可以鸟叫 但不要重复写代码public function speak(){echo "鸟叫";}


高手给讲讲!!!!急呀 经理总说我代码重复率太高了~~~~~


------解决方案--------------------
忘了要继承person类,小改一下

PHP code
class yrPerson extends person{
    //添加口技方法...
    public function show($a){
        $func=Factory::func($a);
        return $func->speak();
    }
}

$person=new yrPerson();
$person->speak();        //自己说话
$person->show('dog');    //学狗叫
$person->show('bird');    //学鸟叫
//接着学... <div class="clear">
                 
              
              
        
            </div>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
function是什么意思function是什么意思Aug 04, 2023 am 10:33 AM

function是函数的意思,是一段具有特定功能的可重复使用的代码块,是程序的基本组成单元之一,可以接受输入参数,执行特定的操作,并返回结果,其目的是封装一段可重复使用的代码,提高代码的可重用性和可维护性。

iOS的developer版和public版有什么区别?iOS的developer版和public版有什么区别?Mar 01, 2024 pm 12:55 PM

每年Apple发布新的iOS和macOS大版本之前,用户都可以提前几个月下载测试版抢先体验一番。由于公众和开发人员都使用该软件,所以苹果公司为两者推出了developer和public版即开发者测试版的公共测试版。iOS的developer版和public版有什么区别呢?从字面上的意思来说,developer版是开发者测试版,public版是公共测试版。developer版和public版面向的对象不同。developer版是苹果公司给开发者测试使用的,需要苹果开发者帐号才可以收到下载并升级,是

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

"enumerate()"函数在Python中的用途是什么?"enumerate()"函数在Python中的用途是什么?Sep 01, 2023 am 11:29 AM

在本文中,我们将了解enumerate()函数以及Python中“enumerate()”函数的用途。什么是enumerate()函数?Python的enumerate()函数接受数据集合作为参数并返回一个枚举对象。枚举对象以键值对的形式返回。key是每个item对应的索引,value是items。语法enumerate(iterable,start)参数iterable-传入的数据集合可以作为枚举对象返回,称为iterablestart-顾名思义,枚举对象的起始索引由start定义。如果我们忽

MySQL.proc表的作用和功能详解MySQL.proc表的作用和功能详解Mar 16, 2024 am 09:03 AM

MySQL.proc表的作用和功能详解MySQL是一种流行的关系型数据库管理系统,开发者在使用MySQL时常常会涉及到存储过程(StoredProcedure)的创建和管理。而MySQL.proc表则是一个非常重要的系统表,它存储了数据库中所有的存储过程的相关信息,包括存储过程的名称、定义、参数等。在本文中,我们将详细解释MySQL.proc表的作用和功能

Vue.use函数的用法和作用Vue.use函数的用法和作用Jul 24, 2023 pm 06:09 PM

Vue.use函数的用法和作用Vue是一款流行的前端框架,它提供了许多有用的功能和功能。其中之一就是Vue.use函数,它可以让我们在Vue应用中使用插件。本文将介绍Vue.use函数的用法和作用,并且提供一些代码示例。Vue.use函数的基本用法非常简单,只需在Vue实例化之前调用它,并传入要使用的插件作为参数。下面是一个简单的示例://引入并使用插件

在PHP中的file_exists()函数在PHP中的file_exists()函数Sep 14, 2023 am 08:29 AM

file_exists方法检查文件或目录是否存在。它接受要检查的文件或目录的路径作为参数。以下是它的用途-当您需要在处理之前知道文件是否存在时,它非常有用。这样,在创建新文件时使用此函数即可知道该文件是否已存在。语法file_exists($file_path)参数file_path-设置要检查是否存在的文件或目录的路径。必需。返回file_exists()方法返回。如果文件或目录存在,则返回TrueFalse,如果文件或目录不存在示例让我们看一个检查“candidate.txt”文件和即使文件

js函数function用法是什么js函数function用法是什么Oct 07, 2023 am 11:25 AM

js函数function用法有:1、声明函数;2、调用函数;3、函数参数;4、函数返回值;5、匿名函数;6、函数作为参数;7、函数作用域;8、递归函数。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.