PHPackages                             gabrieljmj/prototype - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gabrieljmj/prototype

ActiveLibrary

gabrieljmj/prototype
====================

16PHP

Since Nov 1Pushed 11y ago1 watchersCompare

[ Source](https://github.com/GabrielJMJ/Prototype)[ Packagist](https://packagist.org/packages/gabrieljmj/prototype)[ RSS](/packages/gabrieljmj-prototype/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Gabrieljmj\\Prototype
=====================

[](#gabrieljmjprototype)

[![Total Downloads](https://camo.githubusercontent.com/51c6368430dfaf1e89b498babb507295fb2b248cf8ced97835a44000db94c6ef/68747470733a2f2f706f7365722e707567782e6f72672f6761627269656c6a6d6a2f70726f746f747970652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/gabrieljmj/prototype) [![Latest Unstable Version](https://camo.githubusercontent.com/52805a4ee288f56e2bee6f4097195c5a39935deadb8220137fcf5f91c3102c21/68747470733a2f2f706f7365722e707567782e6f72672f6761627269656c6a6d6a2f70726f746f747970652f762f756e737461626c652e706e67)](https://packagist.org/packages/gabrieljmj/prototype) [![License](https://camo.githubusercontent.com/f7a2ac1a0e168c39ed82ed47ebb268578e03d0f2cb1f1949b2c5bd2413147ff8/68747470733a2f2f706f7365722e707567782e6f72672f6761627269656c6a6d6a2f70726f746f747970652f6c6963656e73652e706e67)](https://packagist.org/packages/gabrieljmj/prototype) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/88054c7266f3a6423a58e108606d59789559d5de61a4c4e4d926c0af7aa0365c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4761627269656c4a4d4a2f50726f746f747970652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/GabrielJMJ/Prototype/?branch=master)

This library allows you to create prototypes almost like in JavaScript.

\##Tests Sorry, I know that it is wrong, but I left the tests to do after the library. Why? Because I am having problems to write them.

\##1. Creating an object Objects are created with functions. These functions will return an object. All objects are registred on a class called `\Gabrieljmj\Prototype\Prototype`.

```
require_once 'autoload.php';

use Gabrieljmj\Prototype\Prototype;

function Person() {
    return Prototype::getInstance()->prot('Person');
}
```

To set methods, you need set as global the variable `$self` and use like you use `$this` on OOP:

```
Person()->on = 1;

Person()->setName = function ($name) {
    global $self;
    $self->name = $name;
};

Person()->getName = function() {
    global $self;
    return $self->name;
};
```

So you can instance this and execute the methods and get the propeties:

```
$user1 = new Person();
$user1->setName('Hansel');

$user2 = new Person();
$user2->setName('Gretel');

echo $user1->getName() . ' and ' . $user2->getName(); //Hansel and Gretel
```

\##2. Extending The extending is almost the same of JavaScript. Just set the property `$prototype`:

```
function Employee() {
    return Prototype::getInstance()->prot('Employee');
}

Employee()->prototype = new Person();

Employee()->setJobTitle = function ($jobtitle) {
    global $self;
    $self->jobTitle = $jobtitle;
};

Employee()->getJobTitle = function () {
    global $self;
    return $self->jobTitle;
};

$employee = new Employee();
$employee->setName('Jhon');
$employee->setJobTitle('Developer');

echo 'Hi! My name is ' . $employee->getName() . ' and I work as ' . $employee->getJobTitle() . '.';
//Hi! My name is Jhon and I work as Developer.
```

\###2.1. Instanceof

```
var_dump($person instanceof Employee); //bool(false)
var_dump($employee instanceof Person); //bool(true)
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4fcbdf815749595d3dcfd4fb781e2cac05aa6d132123aa9da889d2c5ca6c8e11?d=identicon)[GabrielJMJ](/maintainers/GabrielJMJ)

---

Top Contributors

[![gabrieljmj](https://avatars.githubusercontent.com/u/2223216?v=4)](https://github.com/gabrieljmj "gabrieljmj (19 commits)")

### Embed Badge

![Health badge](/badges/gabrieljmj-prototype/health.svg)

```
[![Health](https://phpackages.com/badges/gabrieljmj-prototype/health.svg)](https://phpackages.com/packages/gabrieljmj-prototype)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
