get_defined_functions
get_defined_functions(): array
A snapshot of the process function table: internal (builtins) and user (script-defined) halves - the memory-introspection pair of get_defined_vars.
C C23
#include <ctype.h>
#include <stdio.h>
#include <string.h>
/* C in reverse: a table of function pointers with parallel names is the
classic C answer to "list the functions I have" */
static char buf[64] = {0}; /* zero-initialized */
static const char *greet(const char *w) {
snprintf(buf, sizeof buf, "hi %s", w);
return buf;
}
static const char *shout(const char *w) {
char tmp[64] = {0};
snprintf(tmp, sizeof tmp, "hi %s", w);
for (size_t i = 0; tmp[i]; i++) {
tmp[i] = (char)toupper((unsigned char)tmp[i]);
}
snprintf(buf, sizeof buf, "%s!", tmp);
return buf;
}
int main(void) {
const char *(*table[])(const char *) = {greet, shout};
const char *names[] = {"greet", "shout"};
printf("mine: %s,%s\n", names[0], names[1]);
printf("shout: %s\n", table[1]("php"));
return 0;
}
mine: greet,shout shout: HI PHP!
C++ C++26
#include <cctype>
#include <functional>
#include <iostream>
#include <map>
#include <string>
static std::string greet(const std::string &w) {
return "hi " + w;
}
static std::string shout(const std::string &w) {
std::string s = greet(w);
for (char &ch : s) {
ch = static_cast<char>(std::toupper(static_cast<unsigned char>(ch)));
}
return s + "!";
}
int main() {
// C++ in reverse: a std::function map is the hand-rolled function table
std::map<std::string, std::function<std::string(const std::string &)>> table;
table["greet"] = greet;
table["shout"] = shout;
std::cout << "mine:";
for (const auto &entry : table) {
std::cout << " " << entry.first;
}
std::cout << "\n";
std::cout << "shout: " << table.at("shout")("php") << "\n";
return 0;
}
mine: greet shout shout: HI PHP!
C# v11.0.100
using System;
using System.Collections.Generic;
using System.Linq;
// C# in reverse: no runtime table - a delegate map stands in for it
string Greet(string w) => "hi " + w;
string Shout(string w) => Greet(w).ToUpper() + "!";
var table = new Dictionary<string, Func<string, string>> {
["greet"] = Greet,
["shout"] = Shout,
};
Console.WriteLine("mine: [" + string.Join(", ", table.Keys.OrderBy(k => k, StringComparer.Ordinal)) + "]");
Console.WriteLine("shout: " + table["shout"]("php"));
mine: [greet, shout] shout: HI PHP!
Go v1.27.4
package main
import (
"fmt"
"sort"
"strings"
)
// Go in reverse: no runtime function table - collect funcs in a map when
// you genuinely need name-based dispatch
func greet(s string) string { return "hi " + s }
func shout(s string) string { return strings.ToUpper(greet(s)) + "!" }
func main() {
table := map[string]func(string) string{
"greet": greet,
"shout": shout,
}
names := []string{}
for name := range table {
names = append(names, name)
}
sort.Strings(names)
fmt.Println("mine:", names)
fmt.Println("shout:", table["shout"]("php"))
}
mine: [greet shout] shout: HI PHP!
Java v27.0.1
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.UnaryOperator;
public class Main {
static String greet(String w) { return "hi " + w; }
static String shout(String w) { return greet(w).toUpperCase() + "!"; }
public static void main(String[] args) {
// Java in reverse: no runtime function table - wire method references
// into a map when name-based dispatch is needed
Map<String, UnaryOperator<String>> table = new LinkedHashMap<>();
table.put("greet", Main::greet);
table.put("shout", Main::shout);
System.out.println("mine: " + table.keySet());
System.out.println("shout: " + table.get("shout").apply("php"));
}
}
mine: [greet, shout] shout: HI PHP!
JavaScript v26.13.1
// JS in reverse: no enumerable function table - declarations live on their
// scope (or as globalThis properties in sloppy scripts)
function a44Greet(who) {
return "hi " + who;
}
function a44Shout(who) {
return a44Greet(who).toUpperCase() + "!";
}
console.log("declared:", typeof a44Greet, typeof a44Shout);
console.log("shout:", a44Shout("php"));
declared: function function shout: HI PHP!
PHP v8.6.0
// get_defined_functions: the runtime function table, split into "internal"
// and "user" halves - self-inspection of what this process can call
function a44_greet(string $who): string { return "hi " . $who; }
function a44_shout(string $who): string { return strtoupper(a44_greet($who)) . "!"; }
$fns = get_defined_functions();
echo "keys: ", implode(",", array_keys($fns)), "\n";
echo "user functions: ", count($fns["user"]), "\n";
echo "mine registered: ",
var_export(in_array("a44_greet", $fns["user"], true), true), " ",
var_export(in_array("a44_shout", $fns["user"], true), true), "\n";
echo "strlen is internal: ", var_export(in_array("strlen", $fns["internal"], true), true), "\n";
echo a44_shout("php"), "\n";
keys: internal,user user functions: 2 mine registered: true true strlen is internal: true HI PHP!
Python v3.15.2
# Python in reverse: no built-in function table - inspect + globals()
# lets you rebuild the user-defined half yourself
import inspect
def a44_greet(who):
return "hi " + who
def a44_shout(who):
return a44_greet(who).upper() + "!"
mine = sorted(name for name, obj in globals().items() if inspect.isfunction(obj))
print("mine:", mine)
print("shout:", a44_shout("php"))
mine: ['a44_greet', 'a44_shout'] shout: HI PHP!
Rust v1.99.1
// Rust in reverse: no runtime function table - a vec of fn pointers with
// names is the hand-rolled stand-in
fn greet(w: &str) -> String {
format!("hi {}", w)
}
fn shout(w: &str) -> String {
format!("{}!", greet(w).to_uppercase())
}
fn main() {
let table: Vec<(&str, fn(&str) -> String)> = vec![("greet", greet), ("shout", shout)];
let names: Vec<&str> = table.iter().map(|(name, _)| name).copied().collect();
println!("mine: {:?}", names);
let shout_fn = table.iter().find(|(name, _)| *name == "shout").unwrap().1;
println!("shout: {}", shout_fn("php"));
}
mine: ["greet", "shout"] shout: HI PHP!
TypeScript v26.13.1
// TS in reverse: declarations are typed at compile time; typeof checks
// remain the runtime story
function a44Greet(who: string): string {
return "hi " + who;
}
function a44Shout(who: string): string {
return a44Greet(who).toUpperCase() + "!";
}
console.log("declared:", typeof a44Greet, typeof a44Shout);
console.log("shout:", a44Shout("php"));
declared: function function shout: HI PHP!
Language differences
C: the symbol table is fixed at compile time - at runtime there is only a table of function pointers (shown); "list defined functions" is a linker question (nm/objdump).
C++: same as C - no runtime function table; static reflection has not landed, so name-based dispatch is a hand-written map (shown).
C#: you can enumerate methods via reflection (Assembly.GetTypes + GetMethods), but that is reflection, not a function table; local-function/delegate dispatch uses a hand-written dictionary (shown).
Go: no runtime function table - the runtime package cannot list "all defined functions"; need by-name dispatch, write a map[string]func (shown).
Java: methods are enumerable on Class objects (getDeclaredMethods) but invoking by name needs Method handles or a method-reference table (shown) - introspection yes, function pointers no.
JavaScript: no enumerable function table - functions are first-class values scattered across scopes/globalThis; typeof checks (shown) are the only runtime confirmation.
PHP: get_defined_functions returns a full snapshot of the PROCESS function table: an internal half (hundreds of builtins) and a user half (script-defined; the example asserts exactly 2); paired with get_defined_vars (the variable table) as the memory-introspection duo. Teaching point: the exclude_disabled parameter is deprecated since 8.5 - disabled functions leave the function table at compile time, so the parameter has no effect.
Python: no built-in table, but globals() + inspect.isfunction rebuilds the user-function list exactly (shown); dir(module) is the module-scoped equivalent.
Rust: no function table - symbols dispatch statically at compile time; a vec of fn pointers (shown) is the zero-cost "functions as data" shape.
TypeScript: same as JS; the typeof f === "function" runtime check and compile-time declarations each cover one side (shown).