1

Problem:

I did some research to figure out how you could get a list of all function names in PHP in a text string but without full success. I used get_defined_functions() to get a list of functions but it does not return variable handling functions (see http://php.net/manual/en/ref.var.php), misc functions like die() (see http://php.net/manual/en/ref.misc.php), some string functions like echo (see http://php.net/manual/en/ref.strings.php) and functions like array().

Code:

$arr = get_defined_functions(); 

foreach ($arr['internal'] as $key => $value) 
{ 
    echo $value . ', ';
} 

Desired output:

To get all predefined functions in a text string.

2 Answers 2

1

for all functions, use this code:

<?php 

foreach(get_loaded_extensions() AS $module) {

 echo "<pre>"; print_r(get_extension_funcs ($module)); echo "</pre>";

}

?>

NOTE: "echo", "die"... are language constructs. There is no way to get them via function.

http://php.net/manual/en/reserved.keywords.php

Here is a array:

<?php
$keywords = array('__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor');

$predefined_constants = array('__CLASS__', '__DIR__', '__FILE__', '__FUNCTION__', '__LINE__', '__METHOD__', '__NAMESPACE__', '__TRAIT__');
?>
Sign up to request clarification or add additional context in comments.

4 Comments

Why does this not print out the function array()?
@kexxcream array() is also a language construct
@surfer190 I see, why is it organized under array functions? php.net/manual/en/function.array.php
I think of them as constructors, and I view constructors as functions. They are functions of the language as they do work. . It is rather confusing and that is maybe why it is presented as a function.
1

get_defined_function() returns built-in (internal) and user-defined functions.

echo is not actually a function (it is a language construct) from php docs

die and array are also a language construct

A question highlighting the defference between language constructs and built in methods is here. They are basically reserved keywords and basic elements of the programming language.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.