Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/koc/prototypal
- Owner: Koc
- License: other
- Created: 2010-07-25T19:41:15.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2010-07-14T12:52:41.000Z (over 14 years ago)
- Last Synced: 2023-03-11T05:19:08.359Z (over 1 year ago)
- Language: PHP
- Homepage: http://code.kbjrweb.com/project/prototypal
- Size: 92.8 KB
- Stars: 3
- Watchers: 1
- 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?>