An interesting preprocessor for PHP was w3coded developer c PiHiPi which tried to add useful features to the w3coded developer c language like JSON like array syntax, rather w3coded developer c than needing to write array() every time. w3coded developer c Unfortunately, the author has pulled it., w3coded developer c 3 w3coded developer c w3coded developer c @rjmunro, macros are cuddly. w3coded developer c Embrace them. (I prefer simple text-replace w3coded developer c ones.) PHP is a very neat language so there's w3coded developer c less need for them than in other languages, but w3coded developer c they're nifty for shortening and simplifying w3coded developer c largish blocks of code, making it more readable. w3coded developer c If Objective-C didn't have macros I'd become w3coded developer c homicidal. w3coded developer c – Henrik Erlandsson w3coded developer c May 9 '12 at 11:29 w3coded developer c , w3coded developer c w3coded developer c While certainly a valid answer, I maybe w3coded developer c edited out too much of the original question, as w3coded developer c it involves opening a new scope directly after w3coded developer c the macro. Brb, editing. w3coded developer c – Xeo w3coded developer c May 28 '11 at 17:22 w3coded developer c ,Disclaimer: Well, this is not exactly w3coded developer c preprocessor macro, but due to "dynamic" nature w3coded developer c of PHP, preprocessors are not needed/used. w3coded developer c Instead however, you are able to wrap functions w3coded developer c in other functions, like in the example w3coded developer c below.
Yes, you can do this by creating your own function that is being passed also a callback. Here is the example:
// FO function
function fo($b, $c, $callback) {
for ($a = $b; $a < $c; ++$a) {
$callback($a);
}
}
// example of usage
fo(2,10, function($a){
echo '['.$a.']';
});
The above code works in PHP 5.3 and outputs the following:
[2][3][4][5][6][7][8][9]
How about something like:
function my_macro($a, $b, $c) {
$args = func_get_args();
array_shift($args);
array_shift($args);
array_shift($args);
return call_user_func_array("something_horrifically_long_involving_{$a}_{$b}_and_{$c}", $args);
}
CCPP seems to be closest thing available:
#define macroFunction(op1,op2,op3) ((int)op1/((int)op2+(int)op3))
#define hash_hash # ## #
#define showCExamples 1
#if showCExamples
//Reference: http://en.wikipedia.org/wiki/C_preprocessor#Token_concatenation
#define MYCASE(item,id) \
case id: \
item##_##id = id;\
break
switch(x) {
MYCASE(widget,23);
}
Last Update : 2023-09-22 UTC 14:08:23 PM
Last Update : 2023-09-22 UTC 14:08:14 PM
Last Update : 2023-09-22 UTC 14:07:54 PM
Last Update : 2023-09-22 UTC 14:07:34 PM
Last Update : 2023-09-22 UTC 14:07:25 PM
Last Update : 2023-09-22 UTC 14:06:46 PM
Last Update : 2023-09-22 UTC 14:06:29 PM