本篇文章是对php中类常量的使用进行了详细的分析介绍,需要的朋友参考下
注意:不像其他的面向对象编程语言,在php中,虚拟主机,类不能对某个属性变量使用final修饰符。
如果要声明某个属性为常量,香港服务器租用,香港服务器,可以使用const关键字,并且无需使用美元符号作为变量名前缀,也无需使用访问权限修饰符。常量意味着虽然可以访问该变量,但不能修改该变量的值。例如下边的代码声明了常量属性con_var:
复制代码 代码如下:
class Foo{
const con_var="常量属性的值不能被修改
";
public function method_a(){
echo (self::con_var);
}
}
echo(Foo::con_var);
$myFoo=new Foo();
echo ($myFoo->method_a());
?>
常量属性不能使用对象访问,仅能使用类访问,在类本体内,可以使用“self::常量名”,在类本体外可以使用“类名::常量名”。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

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

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