1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00
psalm/tests/fixtures/DestructiveAutoloader/autoloader.php
Bruce Weirdan 205fdd197e
Wrap entrypoints into IIFE to protect their variables (#5366)
* Wrap entrypoints into IIFE to protect their variables

Fixes vimeo/psalm#5359

* Add tests for Psalm variable isolation

* Capture environment before registering autoloader
2021-03-11 00:14:22 -05:00

22 lines
516 B
PHP

<?php
// attempt to destroy some variables Psalm entrypoint may be using
// this will run when autoloader is being registered
foreach ($GLOBALS as $key => $_) {
if ($key === 'GLOBALS') {
continue;
}
$GLOBALS[$key] = new Exception;
}
spl_autoload_register(function() {
// and destroy vars again
// this will run during scanning (?)
foreach ($GLOBALS as $key => $_) {
if ($key === 'GLOBALS') {
continue;
}
$GLOBALS[$key] = new Exception;
}
});