You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using this library you can dinamcally add methods to classes, as in the following example:
5
6
```php
6
7
use skrtdev\Prototypes\Prototypeable;
@@ -21,10 +22,11 @@ Output is `What a nice way to use PHP`
21
22
22
23
### Main Features
23
24
24
-
- 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.
25
-
- Supports **static** methods too, and you can access `self` and `static` too.
26
-
- A native-like `\Error` will be thrown when trying to call a non-existent method.
27
-
- 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()`).
25
+
- 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.
26
+
- Supports **static** methods too, and you can access `self` and `static` too.
27
+
- A native-like `\Error` will be thrown when trying to call a non-existent method.
28
+
- 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()`).
29
+
- Ability to use any kind of `callable`s, not just `Closure`s.
28
30
29
31
### Check if a Class is Prototypeable
30
32
@@ -44,17 +46,15 @@ The `Prototypes` class itself is `Prototypeable`, how strange.
44
46
45
47
### Known issues
46
48
47
-
- 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)
48
-
- You won't be able to use [named arguments](https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments) in Prototypes methods, as `array unpacking` doesn't work with string keys [yet](https://wiki.php.net/rfc/array_unpacking_string_keys).
49
-
- You can't override already-prototyped methods, but this will be added soon.
50
-
- 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`.
49
+
- 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)
50
+
- You won't be able to use [named arguments](https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments) in Prototypes methods, as `array unpacking` doesn't work with string keys [yet](https://wiki.php.net/rfc/array_unpacking_string_keys).
51
+
- You can't override already-prototyped methods, but this will be added soon.
52
+
- 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`.
51
53
52
54
### Future scope
53
55
54
-
- Add the ability to use `callable`s instead of `Closure`s.
55
-
- Use `class_parent()` to implement some kind of `Inheritance`. This may slow up calling prototypes in classes with a long hierarchy.
56
-
- Maybe add the ability to add a method to a class without adding it to his children. (does it make sense?)
57
-
- Allow to add all methods of a normal/anonymous class into a Prototypeable one (Using `Reflection`?).
58
-
- Add ability to use some kind of [Attributes](https://www.php.net/manual/en/language.attributes.overview.php) to functions, classes and methods in order to add them as methods to a class, instead of manually adding them.
59
-
- Add the ability to define prototype methods that has been already defined as prototypes, overwriting them.
60
-
- Add the ability to define prototypes for all the Prototypeable classes. (do you see any use cases?)
56
+
- Use `class_parent()` to implement some kind of `Inheritance`. This may slow up calling prototypes in classes with a long hierarchy.
57
+
- Maybe add the ability to add a method to a class without adding it to his children. (does it make sense?)
58
+
- Allow to add all methods of a normal/anonymous class into a Prototypeable one (Using `Reflection`?).
59
+
- Add the ability to define prototype methods that has been already defined as prototypes, overwriting them.
60
+
- Add the ability to define prototypes for all the Prototypeable classes. (do you see any use cases?)
0 commit comments