2 introduces the private and public keywords that control visibility of functions and variables
within a class. These are discussed in a little more depth in the next section. As you can see, from Listing 17.2,
we have created two member variables (1) which are set to their initial values using the constructor (3).
Public, protected and private visibility
As we have noted, a class can have functions and variables. This grouping is useful in its own right to help
organize code, but really comes into its own when we add information hiding to the mix. Information hiding is
the ability to mark class functions and variables as invisible outside the class boundary. This leads to more
Licensed to Menshu You
Zend Framework in Action (Ch01) Manning Publications Co. 51
maintainable code as each class ???publishes??? an API for other classes to use, but is free to implement that API
however it would like to.
There are three keywords involved: public, protected and private and follow the same usage as other
Object Oriented languages such as C++, Java or C#:
public: available from any scope
protected: only available from with the class or any of its children
private: only available within the class itself
The final keyword is similar to the public keywords, except that child classes cannot override it.
Pages:
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371