search
HomeBackend DevelopmentPHP Tutorial关于php承袭的疑惑

关于php继承的疑惑

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpclass A {    [color=#FF0000]private[/color] $name = "Nciaer";    public function say() {        echo $this -> name . "<br>";    }}class B extends A {    public $name = "Fansa";}$b = new B();$b -> say();?>

输出结果:
Nciaer
----------------------------

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpclass A {    [color=#FF0000]public[/color] $name = "Nciaer";    public function say() {        echo $this -> name . "<br>";    }}class B extends A {    public $name = "Fansa";}$b = new B();$b -> say();?>


输出结果:
Fansa


为什么父类变量$name为public的时候,$b调用成员方法say()输出子类的$name;
当父类变量$name为private时,$b调用成员方法say()输出父类的$name;

------解决方案--------------------
private 私有的
怎么能被继承呢?
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
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"

Java 函数的访问权限修饰符之 public 使用指南Java 函数的访问权限修饰符之 public 使用指南Apr 26, 2024 am 08:39 AM

Javapublic访问权限修饰符允许函数从任何位置访问,用于声明公共API、定义跨包或类共享的工具和实用程序。具体用法如下:语法:public返回值类型函数名称(参数列表){...}场景:需要从任何地方访问的函数、公共API中的方法、共享的工具或实用程序

Vue3中setup怎么添加nameVue3中setup怎么添加nameMay 13, 2023 am 09:40 AM

Vue3中name有什么用呢?1.在递归组件的时候需要定义name2.配合keep-aliveincludeexclude可以缓存组件3.在Vue有报错或者调试的时候可以看到组件的nameVue3定义name1.自动生成只要在script开启setup语法糖模式单文件组件会自动根据文件名生成对应的name选项例如Tree.vue那他的name就是Tree自动生成,这样做有一个弊端如果想修改name需要修改组件名称如果有地方import该组件需要一并修改。2.在开启一个script用来定义name

Java程序展示不同的访问级别Java程序展示不同的访问级别Aug 19, 2023 pm 10:09 PM

Accessmodifiersareusedtosetthefeatureofvisibilityofsomeparticularclasses,interfaces,variables,methods,constructors,datamembers,andthesettermethodsinJavaprogramminglanguage.在Java环境中,我们有不同类型的访问修饰符。默认-如果我们声明一个函数,它只会在特定的包中可见。Private-如果我们声明一个函数,它只能在特定的类中可

php拿不到name怎么办php拿不到name怎么办Nov 24, 2022 am 09:56 AM

php拿不到name是因为当表单元素的name和id的值不一样的时候,浏览器是不能识别的,其解决办法:1、检查部分表单元素和框架元素是否用了name;2、检查只能赋ID不能赋name的元素;3、针对多选框checkbox,可使用“join(',', $__POST['name'])”组成数据。

java中的public修饰符怎么用java中的public修饰符怎么用Apr 18, 2023 pm 06:04 PM

1、任何其他类都可以访问被声明为public的类、方法、构造方法和接口。2、若相互访问的public类分布在不同的包中,则需要导入相应public类所在的包。由于类的继承,所有的公共方法和变量都可以由其子类继承。实例publicclassdemo1{publicstaticvoidmain(String[]args){Personp1=newPerson();p1.fn();System.out.println(p1.a);//100System.out.println(p1.scorce);/

Google Pixel 9a: Leak points to larger casing and four colorsGoogle Pixel 9a: Leak points to larger casing and four colorsOct 03, 2024 am 06:04 AM

The new design of the Google Pixel 9a has already been seen in initial photos and renders over the past few weeks, and nowAndroid Headlineshas just uncovered the exact dimensions and colors of the mid-range smartphone. The Pixel 9a measures 154 x 73

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),