mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2025-01-22 05:11:39 +01:00
Ensure compatibility with multiple autoloaders
Running a .phar or regular PHP executable that requires and includes its own version of php-parser will cause a "cannot redeclare class" error if said executable also includes the autoloader of the current working directory.
This commit is contained in:
parent
251e689283
commit
d225555830
@ -7,14 +7,25 @@ namespace PhpParser;
|
|||||||
*/
|
*/
|
||||||
class Autoloader
|
class Autoloader
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Whether the autoloader has been registered.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected static $registered = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers PhpParser\Autoloader as an SPL autoloader.
|
* Registers PhpParser\Autoloader as an SPL autoloader.
|
||||||
*
|
*
|
||||||
* @param bool $prepend Whether to prepend the autoloader instead of appending
|
* @param bool $prepend Whether to prepend the autoloader instead of appending
|
||||||
*/
|
*/
|
||||||
static public function register($prepend = false) {
|
static public function register($prepend = false) {
|
||||||
|
if (static::$registered === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ini_set('unserialize_callback_func', 'spl_autoload_call');
|
ini_set('unserialize_callback_func', 'spl_autoload_call');
|
||||||
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
||||||
|
static::$registered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require __DIR__ . '/PhpParser/Autoloader.php';
|
if (!class_exists('PhpParser\Autoloader')) {
|
||||||
|
require __DIR__ . '/PhpParser/Autoloader.php';
|
||||||
|
}
|
||||||
PhpParser\Autoloader::register();
|
PhpParser\Autoloader::register();
|
Loading…
x
Reference in New Issue
Block a user