Chapter 3. Using PHP classes effectively

 

This chapter covers:

  • 3.1 Visibility: private and protected methods and variables 41
  • 3.2 The class without objects: class methods, variables, and constants 49
  • 3.3 Abstract classes and methods (functions) 56
  • 3.4 Class type hints 57
  • 3.5 Interfaces 60
  • 3.6 Summary 64

From stone axes to passenger airlines, objects—real, tangible ones—are ubiquitous in technology. From that perspective, it’s hardly surprising that software technology has come to depend on virtual objects. Classes, on the other hand, are something else. Naming, putting things into categories or classes, is inherent in natural language, but talking about categories of things and the process of naming is foreign to physical technology. Classes come out of philosophy and mathematics, starting with the ancient Greeks.

The combination of the two is extraordinarily powerful. In modern technology, abstract physics and mathematics are applied to the down-to-earth activity of making stuff. Object-oriented programming repeats this pattern: the conceptual abstraction of classes and the nuts-and-bolts workings of individual objects come together, creating a synergy.

3.1. Visibility: private and protected methods and variables

3.2. The class without objects: class methods, variables, and constants

3.3. Abstract classes and methods (functions)

3.4. Class type hints

3.5. Interfaces

3.6. Summary