Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create and instantiate php classes in php

Shulou Source: shulou.com Published: 2022-06-01 13:10:45 10月18日 Update

This article will explain in detail how to create and instantiate php classes in php. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

1. Creation of a class

Syntax:

Class class name {

/ / attribute

/ / method

/ / constant

}

Classes are made up of properties, methods, and constants. It can be said that classes become properties, methods, and constants.

The naming convention for the class:

1) start with a letter or underscore, followed by an alphanumeric underscore.

2) php keyword cannot be used as class name

3) Class names are not case-sensitive (keywords and class names are not case-sensitive, variable-sensitive)

4) it is suggested to use the method of naming the big hump.

Class Student {} 2. Instantiation of class

Instantiate through the new keyword

Class Student {} stu1 = new Student (); stu2 = new Student; / / parentheses can be omitted about "how to create and instantiate php classes in php" this article is here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Class name instance attribute key keyword constant method article underscore letter more good practical content variable size suggestion beginning parenthesis number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Technology Shulou Tech Info Shulou Information Xiaomi