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.

kexxcream
  • 5,873
  • 8
  • 43
  • 62

2 Answers2

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__');
?>
Henry
  • 597
  • 4
  • 12
  • Why does this not print out the function `array()`? – kexxcream Aug 02 '15 at 10:14
  • @kexxcream `array()` is also a language construct – tread Aug 02 '15 at 10:27
  • @surfer190 I see, why is it organized under array functions? http://php.net/manual/en/function.array.php – kexxcream Aug 02 '15 at 11:01
  • 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. – tread Aug 02 '15 at 11:08
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.

Community
  • 1
  • 1
tread
  • 10,133
  • 17
  • 95
  • 170