public: The method or property can be accessed in any scope, and this is the default. If no access modifier is specified for a property or method, It will be public.
protected: The method or property can only be accessed from a member of the class or inherited class.
private: The method or property can only be accessed from a member of the class, and cannot be accessed from members of the inherited class. Methods or properties marked private can be redefined in inherited classes. Each class can only see its own private methods.
These three modifiers should be sorted from large to small in terms of scope like this:
public→protected→private. The reason why it is said to be in scope is because the class is the same as before us. Like the functions, some attributes and methods are encapsulated in PHP classes. This encapsulation determines the "visibility" of the data, so that we cannot modify the defined properties and methods at will outside the class but can only call them. This is the benefit of encapsulation, and it also improves security. To illustrate the role of these modifiers, please look at the following code:
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><span> ?php </span></span></span></li> <li><span>class myClass{ </span></li> <li class="alt"> <span>public $</span><span class="attribute">public</span><span>=</span><span class="attribute-value">"Public"</span><span>; </span> </li> <li> <span>protected $</span><span class="attribute">protected</span><span>=</span><span class="attribute-value">"Protected"</span><span>; </span> </li> <li class="alt"> <span>private $</span><span class="attribute">private</span><span>=</span><span class="attribute-value">"Private"</span><span>; </span> </li> <li><span>function say_Hello(){ </span></li> <li class="alt"><span>//我现在什么也不做,等下再告诉你 </span></li> <li><span>} </span></li> <li class="alt"><span>} </span></li> <li> <span>$</span><span class="attribute">obj</span><span>=</span><span class="attribute-value">new</span><span> myClass(); </span> </li> <li class="alt"> <span>echo $obj-</span><span class="tag">></span><span>public; </span> </li> <li> <span>//echo $obj-</span><span class="tag">></span><span>protected; </span> </li> <li class="alt"> <span>//echo $obj-</span><span class="tag">></span><span>private; </span> </li> <li> <span class="tag">?></span><span> </span> </li> <li class="alt"><span class="tag"><span> ?php </span></span></li> <li><span>class myClass{ </span></li> <li class="alt"> <span>public $</span><span class="attribute">public</span><span>=</span><span class="attribute-value">"Public"</span><span>; </span> </li> <li> <span>protected $</span><span class="attribute">protected</span><span>=</span><span class="attribute-value">"Protected"</span><span>; </span> </li> <li class="alt"> <span>private $</span><span class="attribute">private</span><span>=</span><span class="attribute-value">"Private"</span><span>; </span> </li> <li><span>function say_Hello(){ </span></li> <li class="alt"><span>//我现在什么也不做,等下再告诉你 </span></li> <li><span>} </span></li> <li class="alt"><span>} </span></li> <li> <span>$</span><span class="attribute">obj</span><span>=</span><span class="attribute-value">new</span><span> myClass(); </span> </li> <li class="alt"> <span>echo $obj-</span><span class="tag">></span><span>public; </span> </li> <li> <span>//echo $obj-</span><span class="tag">></span><span>protected; </span> </li> <li class="alt"> <span>//echo $obj-</span><span class="tag">></span><span>private; </span> </li> <li> <span class="tag">?></span><span> </span> </li> </ol>
By running the above example we get a "Public", but when you When you remove the comment of //echo $obj->private;, you will get the following error: Fatal error: Cannot access protected property myClass::$protected in E:apachehtdocsexamplefile.php on line 13.
You can see that we cannot access the attribute definitions of the class at will, that is, we cannot modify some operations that have been defined in the encapsulation of the PHP class. This is visibility. We don't know "outside" what members are in this class, because these members may not be visible to other classes.
Of course, if we must access or modify properties defined as "private", we can also use the system methods provided by PHP: _get() and _set(). I will learn more about this later, because now I only have an understanding of it.

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

Win11系统下如何显示文件后缀?详细解读在Windows11操作系统中,文件后缀是指文件名后面的点及其后面的字符,用来表示文件的类型。在默认情况下,Windows11系统会隐藏文件的后缀,这样在文件资源管理器中只能看到文件的名称而无法直观地了解文件的类型。然而,对于一些用户来说,显示文件后缀是非常必要的,因为它能帮助他们更好地辨识文件类型以及进行相关操

随着互联网的不断发展,人们越来越离不开浏览器。而在浏览器中,大家都会或多或少用到cookie这个东西。然而,很多人并不知道cookie数据在哪个文件夹中,今天就来详细解读一下。首先,我们需要了解cookie是什么。简单来说,cookie是由浏览器存储的一段文本信息,用于保存用户在浏览器中的一些个人设置或者记录用户的历史操作等等。当用户再次打开同一个网站时,c

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

去除方法:1、使用substr_replace()函数将首位数字替换为空字符串即可,语法“substr_replace($num,"",0,1)”;2、用substr截取从第二位数字开始的全部字符即可,语法“substr($num,1)”。

LinuxBashrc是Linux系统中的一个配置文件,用于设置用户的Bash(BourneAgainShell)环境。Bashrc文件存储了用户登录时所需的环境变量、启动脚本等信息,可以定制化用户的Shell环境。在Linux系统中,每个用户都有一个对应的Bashrc文件,位于用户的家目录下的隐藏文件夹中。Bashrc文件的作用主要有以下几点:设置环

php有操作时间的方法。php中提供了丰富的日期时间处理方法:1、date(),格式化本地日期和时间;2、mktime(),返回日期的时间戳;3、idate(),格式化本地时间为整数;4、strtotime(),将时间字符串转为时间戳等等。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
