Skip to content

ptrofimov/jslikeobject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fn - dynamic objects a-la Javascript in PHP

Previous version is here https://github.com/ptrofimov/jslikeobject/tree/1.0

So, well... fn is a magic function that transforms PHP anonymous function into function-constructor a-la Javascript. Like in JS, this function is an object and it could instantiate new objects on the own base.

$constructor = fn(function () {        // function-constructor
    $this->property = 1;               // add property
    $this->getProperty = function () { // add method
        return $this->property;
    };
});

$instance = $constructor();            // create new instance

echo $instance->getProperty();         // result: 1

About

Dynamic objects a-la Javascript in PHP with inheritance

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages