Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/koc/prototypal

Prototypal inheritance for PHP classes
https://github.com/koc/prototypal

Last synced: about 6 hours ago
JSON representation

Prototypal inheritance for PHP classes

Awesome Lists containing this project

README

        

h1. Prototypal

Version: 0.1.1-rc
Author: James Brumond

Copyright 2010 James Brumond
Dual licensed under MIT and GPL

h2. Description

Prototypal inheritance for PHP classes

h2. Basic Use

First, any class that you want to utilize prototyping must 1) extend the ProtoObject class (or a child of it) and 2) call the ProtoObject constructor (@ProtoObject::__construct@).

Then, you can access the prototype chain either statically or through an instance of the class; however, if no instance has been created before you try to use prototyping statically, then you must first initialize the prototype chain by calling @init_prototype()@:

one = 'foo';

$my_object = new MyClass();

echo $my_object->one; // outputs: foo

$my_object->prototype->one = 'bar';

echo $my_object->one; // outputs: bar

?>

Prototypes can be methods, as well. Every prototype method must have a first parameter (eg. @$self@) in order to access the object in question (much the same way python methods work).

two = function($self) {

echo $self->one;
};

$my_object->two(); // outputs bar

?>