Callable function as variable
// Execute the screen specific preprocess function.
$preprocess_func = 'sample_module_preprocess_screen__' . $screen;
if (is_callable($preprocess_func)) {
$preprocess_func($variables);
}Magic Variables
These are the magic variables I used a lot in php coding.
| Name | Description |
|---|---|
| __LINE__ | Good for debugging with var_dump(). |
| __FILE__ | The full path and filename. |
| __DIR__ | The directory of the file. |
| __FUNCTION__ | The function name. |
Closures
Closures is the anonymous function in PHP. We can use it in the callback.
$greetings = array_map(function($name) {
return 'Hello ' . $name;
}, ['John', 'Eric', 'Josh']);
print_r($greetings);