简体   繁体   中英

rename lambda function (php)

I build a (so far) pretty nice templating mechanism for a cms. Now I also added a set of developer tools to the UI for a better UX during development. 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.

Question: Is there a way/work around to give meaningful names to lambda functions in php?

This reference might be able to point you in the right direction: http://php.net/manual/en/functions.anonymous.php


 $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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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