PHPackages                             skrtdev/prototypes - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. skrtdev/prototypes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

skrtdev/prototypes
==================

A simple library that make possible to dinamically add methods to classes

v1.1(4y ago)1492MITPHPPHP ^7.4 | ^8

Since Jun 7Pushed 4y ago1 watchersCompare

[ Source](https://github.com/skrtdev/prototypes)[ Packagist](https://packagist.org/packages/skrtdev/prototypes)[ RSS](/packages/skrtdev-prototypes/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Prototypes
==========

[](#prototypes)

> Dinamically add methods to PHP classes

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6006717560e7d356dd3b64fdae98ec22bc30f24d266a7679b24f67ee10660a8c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736b72746465762f70726f746f74797065732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/skrtdev/prototypes/?branch=master) [![Build Status](https://camo.githubusercontent.com/f45b584b4b34ce7da6ca6e22f097179bae1def49bc52de819f68beb1c9a956c7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736b72746465762f70726f746f74797065732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/skrtdev/prototypes/build-status/master) [![Codacy Badge](https://camo.githubusercontent.com/eb0a5417bb1f4edd1df12c5aab14a1ae40adb4bf9cf51655edcef519a8d6f4a1/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6162336138323665633435653435643762636339313063333964663133333161)](https://www.codacy.com/gh/skrtdev/prototypes/dashboard?utm_source=github.com&utm_medium=referral&utm_content=skrtdev/prototypes&utm_campaign=Badge_Grade) [![php version](https://camo.githubusercontent.com/67e0c00cbf6d0d823297efff2d2fdf907077cd7889e2391f39af5d529d40ac46/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e342d626c756576696f6c6574)](https://camo.githubusercontent.com/67e0c00cbf6d0d823297efff2d2fdf907077cd7889e2391f39af5d529d40ac46/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e342d626c756576696f6c6574)
Using this library you can dinamcally add methods to classes, as in the following example:

```
use skrtdev\Prototypes\Prototypeable;

class MyClass{
    use Prototypeable;
}

MyClass::addMethod('wow', function () {
    return "What a nice way to use PHP";
});

$instance = new MyClass();

echo $instance->wow();
```

Output is `What a nice way to use PHP`

### Main Features

[](#main-features)

- Closures are bound to the original object, so you can access `$this` inside closures in the same way as you do when writing a normal method for that class.
- Supports **static** methods too, and you can access `self` and `static` too.
- A native-like `\Error` will be thrown when trying to call a non-existent method.
- A `skrtdev\Prototypes\Exception` will be thrown if class method already exists, is a prototype, class does not exist or isn't Prototypeable (when using `skrtdev\Prototypes\Prototypes::addMethod()`).
- Ability to use any kind of `callable`s, not just `Closure`s.
- Ability to use [named arguments](https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments) in Prototypes methods.

### Check if a Class is Prototypeable

[](#check-if-a-class-is-prototypeable)

You may need to know if a class is `Prototypeable` before trying to add methods to it.

You can use `isPrototypeable` method:

```
use skrtdev\Prototypes\Prototypes;

var_dump(Prototypes::isPrototypeable($instance::class)); // you must pass the class name as string (use get_class() in php7.x)
var_dump(Prototypes::isPrototypeable(MyClass::class));
```

### Fun fact

[](#fun-fact)

The `Prototypes` class itself is `Prototypeable`, how strange.

### Known issues

[](#known-issues)

- This library does not have `Inheritance`: you won't be able to use Prototypes methods defined for a class in his child classes. (this is going to be added soon)
- You can't override already-prototyped methods, but this will be added soon.
- Any kind of `Error/Exception`(s) look a bit strange in the Stack traces, and method name is hidden. Maybe there is a solution; if you find it, feel free to open an `Issue/Pull Request`.

### Future scope

[](#future-scope)

- Use `class_parent()` to implement some kind of `Inheritance`. This may slow up calling prototypes in classes with a long hierarchy.
- Maybe add the ability to add a method to a class without adding it to his children. (does it make sense?)
- Allow to add all methods of a normal/anonymous class into a Prototypeable one (Using `Reflection`?).
- Add the ability to define prototype methods that has been already defined as prototypes, overwriting them.
- Add the ability to define prototypes for all the Prototypeable classes. (do you see any use cases?)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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.

###  Release Activity

Cadence

Every ~20 days

Total

2

Last Release

1785d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ed675ca5cde9cac5fa76de9023a8d3c4ae2b8837f600c4b5c242dc05a016c55?d=identicon)[skrtdev](/maintainers/skrtdev)

---

Top Contributors

[![skrtdev](https://avatars.githubusercontent.com/u/64538010?v=4)](https://github.com/skrtdev "skrtdev (16 commits)")

---

Tags

classhacktoberfestmethodsphpprototypes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/skrtdev-prototypes/health.svg)

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

###  Alternatives

[humanmade/hm-rewrite

HM\_Rewrite is a wrapper for the WordPress WP Rewrite system. http://hmn.md/wordpress-rewrite-rules-hm-core-style/

16115.9k](/packages/humanmade-hm-rewrite)[jayanka/patch-manager

A magento extension to maintain data patches

232.4k](/packages/jayanka-patch-manager)[tapp/filament-progress-bar-column

Add beautiful, color-coded progress bars to your Filament table columns. Perfect for inventory, tasks, storage, and any progress metrics without writing custom views.

124.5k](/packages/tapp-filament-progress-bar-column)

PHPackages © 2026

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