O'Reilly logo

PHP Quick Scripting Reference by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 9

image

Class

A class is a template used to create objects. To define one the class keyword is used followed by a name and a code block. The naming convention for classes is 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, while methods are functions which define what the object can do. Properties are also known as fields or attributes in other languages. In PHP, they must have an explicit access level specified. The public access level is used below, which gives unrestricted access to the property. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required