Section 3.3. Declaring a Class


3.3. Declaring a Class

You might have noticed from the previous example that declaring a class (an object template) is simple. You use the class keyword, give the class a name, and list all the methods and properties an instance of this class should have:

 class MyClass {     ... // List of methods     ...     ... // List of properties     ... } 

You may have noticed that, in front of the declaration of the $name property, we used the private keyword. We explain this keyword in detail later, but it basically means that only methods in this class can access $name. It forces anyone wanting to get/set this property to use the getName() and setName() methods, which represent the class's interface for use by other objects or source code.



    PHP 5 Power Programming
    PHP 5 Power Programming
    ISBN: 013147149X
    EAN: 2147483647
    Year: 2003
    Pages: 240

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net