I’m able to check whether a string corresponds to a “reserved keyword“, such as “if”, “for” and “else”, with this code (given by a Stack Exchange user in a previous question):
function is_reserved_php_keyword($string)
{
$tokens = token_get_all('<?php ' . $string . '; ?>');
return reset($tokens[1]) !== T_STRING;
}
Although a bit “hacky”, it seems to work flawlessly for PHP keywords.
However, I wish to also be able to check if a string corresponds to:
- A built-in (not just “any existing”) PHP function, including “mb_strpos” and “dl”.
- A “special global variable” such as “$argc”, “$argv”, “$_GET”, “$_POST”, “$php_errormsg”, etc.
I want to avoid creating a hardcoded list of these in my code, as that would require me to perpetually and manually keep this up to date with all future PHP versions, even if I manage to figure out all the currently existing ones.
I’ve looked long and hard in both the manual and online for something like this without any luck. Maybe somebody knows of a “trick” similar to the above is_reserved_php_keyword() function?
The similar earlier questions sadly have no acceptable answers.
I miraculously, unexpectedly just figured out half of my question on my own:
function is_built_in_php_function($function_name)
{
if (in_array($function_name, get_defined_functions()['internal']))
return true;
return false;
}