As we can define loop templates in C++, for making coding shorter:
#define fo(a,b,c) for( a = ( b ); a < ( c ); ++ a )
Is there any way to do the same in PHP?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Disclaimer: Well, this is not exactly preprocessor macro, but due to “dynamic” nature of PHP, preprocessors are not needed/used. Instead however, you are able to wrap functions in other functions, like in the example below.
Yes, you can do this by creating your own function that is being passed also a callback. Here is the example:
The above code works in PHP 5.3 and outputs the following: