get_declared_classes / get_declared_interfaces / get_declared_traits
get_declared_classes(): array / get_declared_interfaces(): array / get_declared_traits(): array
Runtime class-table introspection: returns every class/interface/trait currently loaded (extension and builtin declarations included, user classes among them); no ordering guaranteed since 7.4; enums count as classes.
C C23
#include <stdio.h>
#include <string.h>
/* C has no runtime-wide class registry: reflect on what you can name,
size/type traits are the only static introspection tools */
struct Widget {
int x;
};
int main(void) {
struct Widget w;
memset(&w, 0, sizeof w); /* zero-initialized buffer */
printf("type is struct, size=%zu\n", sizeof(struct Widget));
printf("value is zeroed=%d\n", w.x == 0);
return 0;
}
type is struct, size=4 value is zeroed=1
C++ C++26
#include <iostream>
#include <string>
#include <typeinfo>
struct Widget {};
int main() {
// C++ introspects statically: typeid/sizeof replace any runtime class table
Widget w;
std::cout << "typeid name known=" << (std::string(typeid(Widget).name()).size() > 0) << '\n';
std::cout << "static size=" << sizeof(Widget) << '\n';
(void)w;
return 0;
}
typeid name known=1 static size=1
C# v11.0.100
using System;
using System.Linq;
using System.Reflection;
class Widget { }
interface IExportable { }
static class Program
{
static void Main()
{
// Assembly.GetTypes() is the closest thing to a declared-class table
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
Console.WriteLine($"Widget listed={types.Any(t => t.Name == "Widget")}");
Console.WriteLine($"IExportable listed={types.Any(t => t.Name == "IExportable")}");
Console.WriteLine($"string builtin={typeof(string).FullName}");
}
}
Widget listed=True IExportable listed=True string builtin=System.String
Go v1.27.4
package main
import (
"fmt"
"reflect"
)
type Widget struct{}
func main() {
// Go has no runtime class table: reflect inspects a known type instead
t := reflect.TypeOf(Widget{})
fmt.Println("name=", t.Name(), "; methods=", t.NumMethod())
fmt.Println("Stringer satisfied=", t.Implements(reflect.TypeOf((*fmt.Stringer)(nil)).Elem()))
}
name= Widget ; methods= 0 Stringer satisfied= false
Java v27.0.1
public class Main {
static class Widget {}
public static void main(String[] args) {
// no JDK API lists every loaded class: scanning is third-party (ClassGraph),
// the standard-library fallback checks individual names reflectively
System.out.println("Widget class known=" + Widget.class.getName().endsWith("Widget"));
try {
Class.forName("java.lang.String");
System.out.println("java.lang.String loaded=yes");
} catch (ClassNotFoundException e) {
System.out.println("java.lang.String loaded=no");
}
}
}
Widget class known=true java.lang.String loaded=yes
JavaScript v26.13.1
// JS has no runtime-wide class registry: typeof on constructors is the probe
class Widget {}
console.log("Widget is a function=", typeof Widget === "function");
console.log("String is a function=", typeof String === "function");
Widget is a function= true String is a function= true
PHP v8.6.0
// get_declared_classes/interfaces/traits list everything ALREADY loaded:
// user declarations appear alongside extension/builtin ones.
class Widget {}
interface Exportable {}
trait IdHelper {}
echo 'Widget listed=', in_array('Widget', get_declared_classes(), true) ? 'yes' : 'no';
echo '; stdClass listed=', in_array('stdClass', get_declared_classes(), true) ? 'yes' : 'no';
echo '; Traversable iface=', in_array('Traversable', get_declared_interfaces(), true) ? 'yes' : 'no';
echo '; IdHelper trait=', in_array('IdHelper', get_declared_traits(), true) ? 'yes' : 'no', "\n";
Widget listed=yes; stdClass listed=yes; Traversable iface=yes; IdHelper trait=yes
Python v3.15.2
# Python has no runtime-wide class registry: the idiom scans namespaces you care about
import inspect
import builtins
class Widget:
pass
builtin_classes = [name for name, obj in vars(builtins).items() if inspect.isclass(obj)]
print("str is builtin class=", "str" in builtin_classes)
print("Widget is ours, not builtin=", "Widget" not in builtin_classes)
str is builtin class= True Widget is ours, not builtin= True
Rust v1.99.1
// Rust has no runtime class table: types are compile-time, std::any is the closest tool
struct Widget;
fn main() {
println!("type name={}", std::any::type_name::<Widget>());
println!("size known statically={}", std::mem::size_of::<Widget>());
}
type name=main::Widget size known statically=0
TypeScript v26.13.1
// TS has no runtime-wide class registry: typeof on constructors is the probe
class Widget {}
console.log("Widget is a function=", typeof Widget === "function");
console.log("String is a function=", typeof String === "function");
Widget is a function= true String is a function= true
Language differences
PHP: this table lists what is LOADED, not what was declared in your source — extension and builtin classes (stdClass, ArrayObject, Exception…) are there from the start, user classes/interfaces/traits append as declared; since 7.4 no ordering is guaranteed at all (parents used to precede children), so always probe with in_array/array_search and never index by position; enums count as classes (an enum is a class); pairs with class_exists (see that entry): use class_exists for a single probe, this family for enumerating the table — the go-to tool for debugging exactly which classes Composer autoload has loaded.
C: no runtime type registry — types exist only at compile time; the only runtime questions are sizeof and registry structures you build yourself; the example shows static introspection via sizeof plus memset zero-init.
C++: typeid().name() yields the compile-time type name (implementation-defined, mangled on GCC/Clang) and sizeof the static size; runtime-wide enumeration is beyond RTTI's limited powers — real enumeration needs code generation or third-party reflection libraries.
C#: Assembly.GetTypes() (the example) is the semantically closest match — enumerate every type in one assembly; across the whole program walk AppDomain.CurrentDomain.GetAssemblies(); note GetTypes throws ReflectionTypeLoadException for unloadable types — filter with Types.Where(t => t != null).
Go: reflect.TypeOf introspects only a KNOWN value — there is no runtime table of all types; the substitute for a full scan is build-time tooling (go/ast source parsing).
Java: the JDK deliberately offers no list-all-loaded-classes API — ClassLoader exposes only restricted entries like getLoadedClasses() (instrumentation required); the ecosystem idiom is ClassGraph/Google Reflections classpath scanning (which scans bytecode, not a runtime table); Class.forName (the example) probes a single name.
JavaScript: no global type table — typeof probes constructors and Object.getOwnPropertyNames(globalThis) lists only global names; module-scoped types are unenumerable.
Python: vars(builtins) + inspect.isclass (the example) enumerates the builtin table; project-wide scans walk sys.modules filtering vars() per module (or via importlib); only imported modules appear in sys.modules — isomorphic to PHP's loaded semantics.
Rust: types are purely compile-time — std::any::type_name::<T>() names only a known type (with its crate path prefix) and there is zero runtime registry; enumerating all types requires proc-macros expanding at compile time (derive/macro-generated registration), which is how reflection crates work.
TypeScript: same as JavaScript — TS types are fully erased after compilation, only constructor functions remain at runtime; enumeration ability is identical to JS.
Teaching anchor: only PHP, Python, and C# (within an assembly) ship a ready-made loaded-types list; in Java/Go/Rust/C/C++/JS types are either fixed at compile time or scattered across namespaces, and a full scan is third-party/build-time work — understanding whether "class table" means a runtime registry or a source-scan result in each language is the point of this entry.