© Mikael Olsson 2021
M. OlssonPHP 8 Quick Scripting Referencehttps://doi.org/10.1007/978-1-4842-6619-9_9

9. Class

Mikael Olsson1  
(1)
Hammarland, Finland
 
A class is a template used to create objects. To define one, the class keyword is followed by a name and a code block. The naming convention for classes is to use mixed case, meaning that each word should be initially capitalized.
class MyRectangle {}
The class body can contain properties and methods. Properties are variables that hold the state of the object, whereas methods are functions that define what the object can do. Properties are also known as fields or attributes in other languages. In PHP, they need to have an explicit access level specified. In the following example, the public access ...

Get PHP 8 Quick Scripting Reference: A Pocket Guide to PHP Web Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.