Permalink
Browse files

bug fix

  • Loading branch information...
kbjr committed Jul 14, 2010
1 parent f09853c commit d5227e576776b709a11111bd7eab3a1bd570c6bb
Showing with 8 additions and 12 deletions.
  1. +5 −5 README.textile
  2. +3 −7 example.php
View
@@ -12,26 +12,26 @@ 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) 2) have a public, static variable $prototype and 3) call the ProtoObject constructor (@ProtoObject::__construct@).
+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@).
<pre><code><?php
class MyClass extends ProtoObject {
-
- public static $prototype = null;
public function __construct() {
- parent::__construct();
+ ProtoObject::__construct();
}
}
?></code></pre>
-Then, you can access the prototype chain either statically or through an instance of the class:
+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()@:
<pre><code><?php
+ MyClass::init_prototype();
+
MyClass::$prototype->one = 'foo';
$my_object = new MyClass();
View
@@ -1,27 +1,23 @@
<?php
-require "prototype.php";
+require "prototypal.php";
class A extends ProtoObject {
-
- public static $prototype = null;
public function __construct() {
- parent::__construct();
+ ProtoObject::__construct();
}
}
class B extends A {
-
- public static $prototype = null;
public function __construct() {
- parent::__construct();
+ ProtoObject::__construct();
}
}

0 comments on commit d5227e5

Please sign in to comment.