Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel
Last active August 27, 2021 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeschinkel/ed4f9594c105dae7371bfce413399948 to your computer and use it in GitHub Desktop.
Save mikeschinkel/ed4f9594c105dae7371bfce413399948 to your computer and use it in GitHub Desktop.
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