pyrsmk/php-class

PHP class loader

1.0.0 2019-03-01 10:23 UTC

This package is auto-updated.

Last update: 2024-11-29 05:33:17 UTC


README

PhpClass is a PHP class loader that allows you to load and instantiate class files on-the-fly. It was created to be able to load classes which names cannot be known before runtime, as ReflectionClass do not support loading from files.

Installing

composer require pyrsmk/php-class

Use

$phpClass = new PhpClass('path/to/a/file.php');
$myObject = $phpClass->instantiate();

If needed, you can retrieve the namespace and the class name from the file without instantiating it :

$phpClass = new PhpClass('path/to/a/file.php');
echo $phpClass->namespace();
echo $phpClass->classname();

License

Released under MIT license.