public
static
|
activateIfCompatible(?string $pharPath = null): void
Must run after the Composer autoloader is registered (the native classes
implement userland interfaces and may extend userland classes, resolved
through it) and before anything could autoload one of the shadowed
classes — a twin already declared cannot be shadowed. Another program that loads PHPStan's phar, Rector for example, passes
the path to that phar: Phar::running() only knows the phar that runs.
Must run after the Composer autoloader is registered (the native classes
implement userland interfaces and may extend userland classes, resolved
through it) and before anything could autoload one of the shadowed
classes — a twin already declared cannot be shadowed. Another program that loads PHPStan's phar, Rector for example, passes
the path to that phar: Phar::running() only knows the phar that runs.
|
#
|
public
static
|
trustOwnTypesIfSuitable(list<string> $argv, ?string $pharPath = null): void
PHPStan's code is verified by PHPStan itself at the strictest level, so
the engine's run-time checks of its parameter and return types re-check
what analysis already proved — at about 8% of the analysis CPU: a
class-typed parameter costs a class lookup and an instanceof on every
call, a typed return the same on the way out. With the extension active
and PHPStan running from a phar, its optimizer pass (TrustedTypes.cpp)
drops those checks from the code compiled out of the phar. Nothing else
is touched: extensions, bootstrap files and the analysed project keep
their checks, including on what they receive from PHPStan and return to
it — a check sits in the callee. What is lost is the TypeError at the boundary when such code passes a
wrong value into PHPStan: it surfaces later, deeper. That is why --debug
keeps the checks — the "run with --debug" advice on internal errors then
yields the original error. PHPUnit never gets here, so the test suites
of PHPStan and of extensions always run fully checked. Must run before the Composer autoloader and preload.php are compiled:
the pass rewrites scripts as they are compiled, so whatever was
compiled earlier keeps its checks. Independent of activateIfCompatible()
— only the version gate matters here. Another program that loads PHPStan's phar, Rector for example, passes
the path to that phar: Phar::running() only knows the phar that runs.
PHPStan's code is verified by PHPStan itself at the strictest level, so
the engine's run-time checks of its parameter and return types re-check
what analysis already proved — at about 8% of the analysis CPU: a
class-typed parameter costs a class lookup and an instanceof on every
call, a typed return the same on the way out. With the extension active
and PHPStan running from a phar, its optimizer pass (TrustedTypes.cpp)
drops those checks from the code compiled out of the phar. Nothing else
is touched: extensions, bootstrap files and the analysed project keep
their checks, including on what they receive from PHPStan and return to
it — a check sits in the callee. What is lost is the TypeError at the boundary when such code passes a
wrong value into PHPStan: it surfaces later, deeper. That is why --debug
keeps the checks — the "run with --debug" advice on internal errors then
yields the original error. PHPUnit never gets here, so the test suites
of PHPStan and of extensions always run fully checked. Must run before the Composer autoloader and preload.php are compiled:
the pass rewrites scripts as they are compiled, so whatever was
compiled earlier keeps its checks. Independent of activateIfCompatible()
— only the version gate matters here. Another program that loads PHPStan's phar, Rector for example, passes
the path to that phar: Phar::running() only knows the phar that runs.
|
#
|