You can define a local function in PHP, but you can only declare it once. This can be achieved by defining and comparing a static variable.
See the following example:
<?php function a() { static $init = true; if ($init) { function b() { } $init = FALSE; } } a(); a();
Alternatively, by checking if a function exists:
<?php function a() { if (!function_exists('b')) { function b() { } } } a(); a();
source share