Download the PHP package mf/callback-parser without Composer
On this page you can find all versions of the php package mf/callback-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package callback-parser
CallbackParser
PHP parser for arrow functions
This library is no longer supported, since the arrow functions are natively in PHP 7.4 - https://www.php.net/manual/en/functions.arrow.php
Table of Contents
- Requirements
- Installation
- Arrow Functions
- How does it work
- Possibly WTF?
- 80:20 - Simple
Requirements
- PHP 7.1
eval()
function for parsing Arrow Functions
Installation:
Arrow Functions
Usage:
With Custom Exception
How does it work?
- it parses function from string and evaluate it with
eval()
Possibly WTF?
This parser can parse an arrow function into PHP to be execute as usual.
But this process could be a little bit more complex than just eval
it.
You can check CallbackParserTest::provideInvalidFunction()
for examples.
Namespaces of parameters
For example namespace of class for given parameter type.
This example above shows an INVALID
arrow function to be parsed (yet?).
Theres more reasons for this is an invalid
one:
- callback is parsed and
eval
ed elsewhere of scope, where you give such a callback - so
CallbackParser
does not knowSimpleEntity
full class name
There is more ways to 'fix' it, like:
- you can register a class map of allowed parameter types and parser could find a relevant one and use a full class name from the map, but IMHO this could be more complex than it should be
- parser could also find a relevant class in you entire project and magically use one of the most relevant, but it's a dark magic and I'd rather avoid it
Question is - is it really necessary?
I dont think so. Because PHP is quite powerful (weak
) and allows you
to use class methods of an object even if you don't know what they are.
But since the original purpose of this parser was to parse a callbacks on Collections,
you have other ways to know and verify a object type in parameter, so you can simply use those methods right away.
Simple simpler and complex still simply - 80:20
IMHO this parser allows you to parse simple functions simply, and you can still write a complex functions like PHP allows you.