PHP-Scoper Patcher for removing prefixes from global functions/classes/traits.
composer require --dev pxlrbt/php-scoper-prefix-remover
Import the required classes either manually or via composer autoloader:
require __DIR__ . '/vendor/autoload.php';
use pxlrbt\PhpScoper\PrefixRemover\IdentifierExtractor;
use pxlrbt\PhpScoper\PrefixRemover\RemovePrefixPatcher;
Extract the functions/classes/traits/interfaces you want the prefix removed from a stub file:
$identifiers = (new IdentifierExtractor())
->addStub('stub-file.php')
->extract();
Add the patcher in the patcher section of PHPScoper and pass the identifiers you extracted earlier:
'patchers' => [
// Some patcher
(new RemovePrefixPatcher($identifiers)),
// More patchers
For removing prefixes from WordPress functions/classes install WordPress stubs.
composer require --dev php-stubs/wordpress-stubs
Then add the stubs file to the extractor:
use pxlrbt\PhpScoper\PrefixRemover\IdentifierExtractor;
$identifiers = (new IdentifierExtractor())
->addStub('vendor/php-stubs/wordpress-stubs/wordpress-stubs.php')
->extract();
There might be issues with new reserved keywords (e.g. readonly as new keyword in PHP 8.1 and WordPress function name). You can set the targeted PHP version by providing a non default lexer like this:
use pxlrbt\PhpScoper\PrefixRemover\IdentifierExtractor;
use PhpParser\Lexer\Emulative;
$identifiers = (new IdentifierExtractor())
->addStub('vendor/php-stubs/wordpress-stubs/wordpress-stubs.php')
->setLexer(new Emulative(['phpVersion' => '8.0']))
->extract();