-
-
Save mikeschinkel/ed4f9594c105dae7371bfce413399948 to your computer and use it in GitHub Desktop.
Idea: Allow PHP class declaration across multiple files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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