I need to pass the $route to its inner function,but failed:
function compilePath( $route )
{
preg_replace( '$:([a-z]+)$i', 'pathOption' , $route['path'] );
function pathOption($matches)
{
global $route;//fail to get the $route
}
}
I’m using php5.3,is there some feature that can help?
I don’t think you can do anything like that in PHP 5.2, unfortunatly — but as you are using PHP 5.3… you could use Closures to get that to work.
To begin, here’s a quick example of using a Closure :
Will display :
Notice the
usekeyword 😉And here’s an example of how you could use that in your specific case :
And you’d get this output :
A couple of notes :
preg_replace_callback, and notpreg_replace— as I want some callback function to be called.$route, with the newusekeyword.preg_replace_callbackto the callback function, and the$route.