|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-03-17 07:59 UTC] kjarli at gmail dot com
Description: ------------ A lot of web applications feature controllers. A controller can be really anything in the form of: - A method in a class - An invokable class - A function - A closure Now what is being doing in Frameworks like Symfony, is that you can have arguments of the action methods injected with some reflection with some fancy resolving if you please. Even though using reflection during run-time, it's a feature that cannot be missed for the purpose of DX (Developer eXperience). To make this faster, I was thinking of caching away the arguments resolved by reflection, this includes name, type (compat between 5 and 7), variadic (false on 5.5), has default and default value. This works fine for pretty much everything _except_ anonymous functions. In order to identity a controller, I can save the class+method or function name. For closures this is not possible because everything is a \Closure and the object hash is no reliable across requests. This means that for anonymous functions I would still have to resolve run-time what the arguments of the function are. With php 7 supporting Anonymous classes will have the same issue. Would it be possible to generate a signature hash of somesort so you can detect the same anonymous class/function across requests? PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 20:00:01 2025 UTC |
I see annotations or attributes as a good and generic approach to solve this issue: ``` $router->add('/hello/{param}', <<route(hello)>> function($param){ return 'response'; }); ``` Link: https://wiki.php.net/rfc/attributes