Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel
Last active Aug 27, 2021
Embed
What would you like to do?
Idea: Allow PHP class declaration across multiple files
// In /index.php
spl_autoload_register(fn($c) => require sprintf( "%s/src/%s.php", __DIR__, $c ));
// In /src/FooBarCms.php
class FooBarCms {}
// In /plugins/my-map/src/MyMap.php
class MyMap {
function display() {}
}
// In /plugins/my-map/extends/FooBarCms.php
extends class FooBarCms {
public $map;
function __construct() {
$this->map = new MyMap;
}
}
// In /plugins/my-map/index.php
spl_autoload_register(fn($c) => require sprintf( "%s/src/%s.php", __DIR__, $c ));
register_class_extends(FooBarCMS::class,__DIR__ . '/extends' );
$cms = new FooBarCms();
$cms->map->display();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment