spl_autoload_functions
spl_autoload_functions(): array
Returns the SPL autoloader registry: every callback pushed by spl_autoload_register, enumerable in registration order - registering writes it, this reads it.
C C23
#include <stdio.h>
/* C in reverse: a registry array of {name, fn} pairs is the hand-rolled
answer; symbols are static, the table is data */
typedef const char *(*loader_fn)(void);
static const char *greet(void) { return "hi"; }
static const char *bye(void) { return "bye"; }
int main(void) {
struct {
const char *name;
loader_fn fn;
} loaders[] = {
{"greet", greet},
{"bye", bye},
};
printf("registered: %s,%s\n", loaders[0].name, loaders[1].name);
printf("loaded: %s\n", loaders[0].fn());
return 0;
}
registered: greet,bye loaded: hi
C++ C++26
#include <functional>
#include <iostream>
#include <map>
#include <string>
int main() {
// C++ in reverse: a std::function registry keyed by name is the
// hand-rolled loader queue
std::map<std::string, std::function<std::string()>> loaders;
loaders["greet"] = [] { return "hi"; };
loaders["bye"] = [] { return "bye"; };
std::cout << "registered: " << loaders.size() << "\n";
for (const auto &entry : loaders) {
std::cout << entry.first << " -> " << entry.second() << "\n";
}
return 0;
}
registered: 2 bye -> bye greet -> hi
C# v11.0.100
using System;
using System.Collections.Generic;
// C# in reverse: assembly loading is explicit (Assembly.Load, load contexts);
// a delegate map is the hand-rolled registry
var loaders = new Dictionary<string, Func<string>> {
["greet"] = () => "hi",
["bye"] = () => "bye",
};
Console.WriteLine("registered: [" + string.Join(", ", loaders.Keys) + "]");
Console.WriteLine("loaded: " + loaders["greet"]());
registered: [greet, bye] loaded: hi
Go v1.27.4
package main
import (
"fmt"
"sort"
)
// Go in reverse: packages link at compile time - no autoload exists;
// a registry map is the idiom when register-by-name is genuinely needed
var loaders = map[string]func() string{}
func register(name string, fn func() string) {
loaders[name] = fn
}
func main() {
register("greet", func() string { return "hi" })
register("bye", func() string { return "bye" })
names := []string{}
for name := range loaders {
names = append(names, name)
}
sort.Strings(names)
fmt.Println("registered:", names)
fmt.Println("loaded:", loaders["greet"]())
}
registered: [bye greet] loaded: hi
Java v27.0.1
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Supplier;
public class Main {
public static void main(String[] args) {
// Java in reverse: no autoloader - ServiceLoader finds META-INF
// providers; a supplier map is the hand-rolled registry
Map<String, Supplier<String>> loaders = new LinkedHashMap<>();
loaders.put("greet", () -> "hi");
loaders.put("bye", () -> "bye");
System.out.println("registered: " + loaders.keySet());
System.out.println("loaded: " + loaders.get("greet").get());
}
}
registered: [greet, bye] loaded: hi
JavaScript v26.13.1
// JS in reverse: no runtime autoloader registry - module resolution is
// fixed at import time; a loader Map is the hand-rolled stand-in
const loaders = new Map();
loaders.set("greeting", () => ({ hello: () => "hi" }));
loaders.set("farewell", () => ({ bye: () => "bye" }));
console.log("registered:", [...loaders.keys()].join(","));
const mod = loaders.get("greeting")();
console.log("loaded:", mod.hello());
registered: greeting,farewell loaded: hi
PHP v8.6.0
// spl_autoload_functions: read back the SPL autoloader queue that
// spl_autoload_register fills; any callable may sit in it
$before = count(spl_autoload_functions()); // 8.0+: always an array
spl_autoload_register(function (string $class): void { /* loader one */ });
spl_autoload_register("var_dump"); // any callable is registrable
$after = spl_autoload_functions();
$n = count($after);
echo "queue grew by ", $n - $before, "\n";
echo "added Closure first: ", $after[$n - 2] instanceof Closure ? "yes" : "no", "\n";
echo "added var_dump second: ", $after[$n - 1] === "var_dump" ? "yes" : "no", "\n";
queue grew by 2 added Closure first: yes added var_dump second: yes
Python v3.15.2
# Python in reverse: the import machinery exposes its finder chain -
# sys.meta_path is the registry to inspect (and extend)
import sys
names = [finder.__name__ for finder in sys.meta_path]
print("meta_path finders:", names)
print("count:", len(names))
meta_path finders: ['BuiltinImporter', 'FrozenImporter', 'PathFinder'] count: 3
Rust v1.99.1
// Rust in reverse: linking is static, so an "autoload queue" is a registry
// of factory functions you build yourself
fn greet() -> &'static str {
"hi"
}
fn bye() -> &'static str {
"bye"
}
fn main() {
let loaders: Vec<(&str, fn() -> &'static str)> = vec![("greet", greet), ("bye", bye)];
let names: Vec<&str> = loaders.iter().map(|(name, _)| name).copied().collect();
println!("registered: {:?}", names);
let greet_fn = loaders.iter().find(|(name, _)| *name == "greet").unwrap().1;
println!("loaded: {}", greet_fn());
}
registered: ["greet", "bye"] loaded: hi
TypeScript v26.13.1
// TS in reverse: type the loader registry - factory functions returning
// typed modules, kept in a Map
interface GreetingModule {
hello: () => string;
}
interface FarewellModule {
bye: () => string;
}
const loaders = new Map<string, () => GreetingModule | FarewellModule>();
loaders.set("greeting", () => ({ hello: () => "hi" }));
loaders.set("farewell", () => ({ bye: () => "bye" }));
console.log("registered:", [...loaders.keys()].join(","));
const mod = loaders.get("greeting")() as GreetingModule;
console.log("loaded:", mod.hello());
registered: greeting,farewell loaded: hi
Language differences
C: no dynamic-load registry - dlopen/dlsym (<dlfcn.h>) is the only runtime entry; register-by-name is always a hand-written table (shown).
C++: same as C - static linking is the norm; a std::function registry (shown) is the standard shape of application-level plugin patterns.
C#: assembly loading is explicit (Assembly.Load, AssemblyLoadContext plugin isolation); by-name dispatch uses a delegate dictionary (shown), with MEF/DI containers as the framework-level answer.
Go: compile-time linking, no autoload - the plugin package (limited platform support) is the only dynamic-load door; a registry map (shown) is the idiomatic substitute.
Java: ServiceLoader (META-INF/services) is the standard discovery mechanism - scanned at startup rather than triggered on demand; by-name registration uses a Supplier table (shown).
JavaScript: module resolution is fixed at import time; there is no runtime autoloader registry - dynamic loading goes through import(), and registry semantics mean hand-writing a Map (shown).
PHP: spl_autoload_functions is the QUERY port of the autoloader registry: every callback pushed by spl_autoload_register (closures, function names, static methods) is enumerable in registration order (the example asserts from the queue tail after registering two); since 8.0 it always returns an array (previously false when inactive). Pairs with spl_autoload_register (A20): registering writes, this reads - spl_autoload_unregister removes.
Python: the import machinery's registry is sys.meta_path (the finder chain, enumerated in the example); the on-demand-loading equivalent is importlib.import_module.
Rust: static linking - "autoload" does not exist; a registry of fn pointers (shown) is the manual form, and real plugins go through trait objects + dynamic-lib crates.
TypeScript: same as JS; import type is compile-time, the runtime registry is still hand-written (shown).