https://github.com/koc/prototypal
Prototypal inheritance for PHP classes
https://github.com/koc/prototypal
Last synced: 4 months ago
JSON representation
Prototypal inheritance for PHP classes
- Host: GitHub
- URL: https://github.com/koc/prototypal
- Owner: Koc
- License: other
- Created: 2010-07-25T19:41:15.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2010-07-14T12:52:41.000Z (about 15 years ago)
- Last Synced: 2025-01-20T11:09:13.373Z (6 months ago)
- Language: PHP
- Homepage: http://code.kbjrweb.com/project/prototypal
- Size: 92.8 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: LICENSE
Awesome Lists containing this project
README
h1. Prototypal
Version: 0.1.1-rc
Author: James BrumondCopyright 2010 James Brumond
Dual licensed under MIT and GPLh2. 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?>