Download the PHP package typhoon/overloading without Composer
On this page you can find all versions of the php package typhoon/overloading. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download typhoon/overloading
More information about typhoon/overloading
Files in typhoon/overloading
Package overloading
Short Description The missing method overloading feature for PHP.
License MIT
Informations about the package overloading
Typhoon Overloading
The missing method overloading feature for PHP.
Installation
composer require typhoon/overloading
Usage
To mark methods handleInt
and handleString
as overloading method handle
,
add #[Overload('handle')]
attribute to handleInt
and handleString
and
call Overload::call()
from handle
. You do not need to pass arguments to Overload::call()
,
this happens automagically. However, return Overload::call()
explicitly if you need to.
After this you will be able to call handle
with any arguments and reach overloading methods
when their signature matches.
What about speed?
Well, using overloading is obviously slower, than calling a method directly, but not awfully slower.
Here's a simple benchmark for the WhateverHandler
:
It's important to understand that memoization plays a very important role here. CLI workers and applications, served
via Roadrunner, for instance, will benefit from this. For PHP-FPM you can enable file cache suitable for OPcaching via
Overload::useFileCache('/path/to/cache');
.
TODO
- [ ] Finish tests.
- [ ] Explain caching in README.
- [ ] Optimize generated code.
- [ ] Inherit attributes from upstream method declarations.
- [ ] Allow to warm up classes.
- [ ] Psalm plugin.
- [ ] PHPStan plugin.
- [ ] Support static analysis types.
All versions of overloading with dependencies
ext-filter Version *