Page 1 of 1

Valid PHP Function Name RegEx

Posted: Sat Jun 20, 2009 6:22 pm
by david64
Hi,

The regex that sets out the boundaries for valid function names in PHP is:

Code: Select all

[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
Does anyone know if there is a quicker to test something against this pattern than preg_match?

Re: Valid PHP Function Name RegEx

Posted: Sat Jun 20, 2009 8:45 pm
by requinix
Perhaps function_exists? That's for functions that already exist of course; for callbacks you should use is_callable.

If you want to check for a possible function name then there's a problem: PHP actually allows just about anything. It's just that the

Code: Select all

function foo
syntax restricts you and you can't really create a function without using that. For example, lambda functions have a null character at the end.

But anyways, there isn't really a better method. How are you using it?