Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // https://github.com/lisachenko/go-prototype-php/blob/master/example.php#L18-L44
- // Constructor for Object class
- {
- function Object($message) {
- $this->hello = $message;
- $this->message = function () {
- echo $this->hello;
- };
- $this->welcome = function ($user) {
- echo $this->hello, ", ", $user;
- };
- }
- }
- $object = new Object('Hello');
- $object->welcome('User'); // Hello, User
- Object::$prototype += [
- 'text' => 'Some text',
- 'showText' => function() {
- echo $this->text;
- }
- ];
- $object->showText(); // Some text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement