Download the PHP package skrtdev/prototypes without Composer
On this page you can find all versions of the php package skrtdev/prototypes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download skrtdev/prototypes
More information about skrtdev/prototypes
Files in skrtdev/prototypes
Download skrtdev/prototypes
More information about skrtdev/prototypes
Files in skrtdev/prototypes
Vendor skrtdev
Package prototypes
Short Description A simple library that make possible to dinamically add methods to classes
License MIT
Package prototypes
Short Description A simple library that make possible to dinamically add methods to classes
License MIT
Please rate this library. Is it a good library?
Informations about the package prototypes
Prototypes
Dinamically add methods to PHP classes
Using this library you can dinamcally add methods to classes, as in the following example:
Output is What a nice way to use PHP
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
andstatic
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 usingskrtdev\Prototypes\Prototypes::addMethod()
). - Ability to use any kind of
callable
s, not justClosure
s. - Ability to use named arguments in Prototypes methods.
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:
Fun fact
The Prototypes
class itself is Prototypeable
, how strange.
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 anIssue/Pull Request
.
Future scope
- Use
class_parent()
to implement some kind ofInheritance
. 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?)
All versions of prototypes with dependencies
PHP Build Version
Package Version
Requires
php Version
^7.4 | ^8
The package skrtdev/prototypes contains the following files
Loading the files please wait ....