Fork me on GitHub
Objective-PHP is a port of the Objective-C (or Objective-J runtime to PHP. This adds the language features of Objective-C nestled nicely inside the syntax of Objective-C. Moka is a port of the Apple Cocoa Frameworks (or Cappuccino).

Categories in Objective-PHP

About Categories

Categories allow the programmer to add methods to classes at runtime. Once a method is added to a class via a Category it is available to all instances of objects of that class from then on. Another important factor of Categories is that they allow the programmer to add methods to classes which are defined in external Frameworks or libraries.

Both class and instance methods can be added to objects, and new instance variables cannot be defined. This is a restriction of Objective-C (as once a class has been compiled its ivars become a C struct of which one is created per class instance and hence adding new ivars at runtime would mean having to change the size of this struct, and this isn’t trivial. Since this restriction does not exist in PHP it would be possible to add ivars via Categories but this features is not currently planned).

Categories override methods with the same Selector that are already defined in a class.

In ObjPHP categories are implemented in a way that means as the parser comes across a definition of one, it creates the necessary runtime calls in the output source to thus add the new methods to the specified objects at runtime.

Implementation Detail

Source Code Links

More Information

Document status: COMPLETE for current version.