Class¶
Basic class definitions begin with the keyword class, followed by a class name, followed by a pair of curly braces which enclose the definitions of the properties and methods belonging to the class.
A class name may be validated with the following regex: ^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$; and by avoiding a list of PHP keywords, such as namespace, class, interface, etc.
<?php
class X {
const CONSTANT = 1;
private $property = 2;
function method() {
/// and more
}
}
?>
See also How to use PHP classes for object-oriented programming.
Related : Readonly, Class Invasion, Const, Class Getter Method, implements, Inheritance, Method, Class Setter Method, Trait, Class Wither Method, Structure, Class Interface Trait Enumeration (CITE), $this, Lazy Objects, Polymorphism, Promoted Properties, Existence, Phptoken, Reflection, Undefined, Base Class, instance, is_a(), Naming Conflict, Non-static
Added in PHP 4.0+