Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

How to Write a Class Statement

You write the PHP class statement to define the properties and methods for the class. The class is the template (pattern) for the object. The class statement has the following general format:

class className
{
 
    Add statements that define the properties
    Add all the methods
}

You can use any valid PHP identifier for the class name, except the name stdClass. PHP uses the name stdClass internally, so you can't use this name.

All the property settings and method definitions are enclosed in the opening and closing curly braces. If you want a class to be a subclass that inherits properties and methods, use a statement similar to the following:

class whiteRose extends Rose
{
    Add the property statements
    Add the methods
}

The object created from this class has access to all the properties and methods of both the whiteRose child class and the Rose class. The Rose class, however, doesn’t have access to properties or methods in the child class, whiteRose. Imagine, the child owns everything the parent owns, but the parent owns nothing of the child's. What an idea.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.