Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. <?php
  2. // https://github.com/lisachenko/go-prototype-php/blob/master/example.php#L18-L44
  3.  
  4. // Constructor for Object class
  5. {
  6.  
  7.     function Object($message) {
  8.  
  9.         $this->hello = $message;
  10.  
  11.         $this->message = function () {
  12.             echo $this->hello;
  13.         };
  14.  
  15.         $this->welcome = function ($user) {
  16.             echo $this->hello, ", ", $user;
  17.         };
  18.     }
  19. }
  20.  
  21. $object = new Object('Hello');
  22.  
  23. $object->welcome('User'); // Hello, User
  24. Object::$prototype += [
  25.     'text'     => 'Some text',
  26.     'showText' => function() {
  27.         echo $this->text;
  28.     }
  29. ];
  30. $object->showText(); // Some text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement