简体   繁体   English

重命名lambda函数(php)

[英]rename lambda function (php)

I build a (so far) pretty nice templating mechanism for a cms. 我为cms构建了一个(到目前为止)相当不错的模板机制。 Now I also added a set of developer tools to the UI for a better UX during development. 现在,我还向UI添加了一组开发人员工具,以便在开发过程中获得更好的UX。 The only problem I'm left with is that I have to use create_function to add my templates, and therefore have lambda_xyz instead of meaningful template or function names. 我唯一剩下的问题是我必须使用create_function添加模板,因此具有lambda_xyz而不是有意义的模板或函数名称。

Question: Is there a way/work around to give meaningful names to lambda functions in php? 问题:有没有办法为php中的lambda函数赋予有意义的名称?

This reference might be able to point you in the right direction: http://php.net/manual/en/functions.anonymous.php 此参考书可能会为您指出正确的方向: http : //php.net/manual/en/functions.anonymous.php


Anonymous functions require PHP 5 >= 5.3.0 匿名函数需要PHP 5> = 5.3.0

 $function_name = 'meaningful_name'; // PHP 5 >= 5.3.0 $$function_name = function(){echo "I am connected to a meaningful name";}; // PHP 4 >= 4.0.1, PHP 5 $$function_name = create_function('', 'echo "I am connected to a meaningful name";'); // Then you can call your function like this $meaningful_name(); 

If this isn't what you are looking for, can you update your question with what you are trying to accomplish in more detail? 如果这不是您要查找的内容,您是否可以通过尝试更详细地完成的事情来更新您的问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM