search
Homephp教程php手册一个完整的PHP类包含的七种语法说明

这篇文章主要介绍了一个完整的PHP类包含的七种语法说明,这些语法包括属性、静态属性、方法、静态方法、类常量、构造函数、析构函数,本文一一给代码示例和详细注

类中的七种语法说明

-属性
-静态属性
-方法
-静态方法
-类常量
-构造函数
-析构函数

'; } // 静态方法 public static function static_stuFunction() { echo 'static_function','
'; } // 构造函数 创建对象时自动调用 public function __construct($stu_name) { $this->stu_name = $stu_name; echo '__construct','
'; } // 析构函数 销毁对象时自动调用 public function __destruct() { echo '__destruct','
'; } } // 实例化类对象 $object = new Student('Tom'); // 对象调用属性 echo $object->stu_name,'
'; // 对象调用静态属性 echo $object::$stu_num,'
'; // 类调用静态属性 echo Student::$stu_num,'
'; // 使用对象分别调用方法和静态方法 $object->stuFunction(); $object->static_stuFunction(); $object::stuFunction(); $object::static_stuFunction(); // 使用类分别调用方法和静态方法 Student::stuFunction(); Student::static_stuFunction(); // 类调用类常量 echo Student::STUDENT,'
';

总结:

对象可以调用属性和静态属性,,类只能调用静态属性。

对象可以调用方法和静态方法,类可以调用方法和静态方法。

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

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

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

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.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version