NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
Packagist
Packagist, #620 most downloaded on Packagist
PHPStan rules to detect disallowed method & function calls, constant, namespace, attribute, property & superglobal usages, with powerful rules to re-allow a call or a usage in places where it should be allowed.
Latest stable
v4.15.0
Last release 1 months ago
13 Oct 2026
Release timing varies
gaps range from 8 days to 4 months
Nearly every release is documented
notes for 58 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
8 years old
88 releases · first in 2018
Drag across the ruler to compare, or tap a release to open it.
More usages of classes, interfaces, enums and traits disallowed with disallowedClasses or disallowedNamespaces are reported: instanceof, first-class c
disallowedClasses or disallowedNamespaces are reported: instanceof, first-class callables like Foo::bar(...), DNF types like (A&B)|null, types of class constants, and interfaces extended by interfaces or implemented by enums (#444)Class, Interface (with the new disallowed.interface identifier), Enum or Trait, also in static calls, extends and implements, which said Namespace before; only use imports keep Namespace because they can also import a namespace (#440, #443 - possible BC break)allowInClassWithMethodAttributes sees attributes on hooks; matching hooks by name like Foo::$bar::get() in allowInMethods is now documented (#441, #445)Suit::Hearts was reported twice, as a class and as an enum, now it's reported once as Enum (#440)ReflectionException when the config had allowInMethodsWithAttributes, allowExceptInMethodsWithAttributes or their aliases (#441)self::, static:: and parent:: calls aren't reported as Namespace self is forbidden. anymore when a wildcard pattern happens to match them (#443)str_contains() isn't used anymore, it doesn't exist on PHP 7.4 (#436)composer.json (#439)PHPStan1Compatibility renamed to PHPStanCompatibility, because it covers older PHPStan 2.x versions too (#441)Possible BC break note: messages and identifiers changed for static calls, extends and implements (Namespace/disallowed.namespace is now Class, Interface, Enum or Trait), for interfaces and traits anywhere else (Class/disallowed.class is now Interface/disallowed.interface or Trait/disallowed.trait), and for enums in type declarations (Class is now Enum). The duplicate Class error for enum cases and constants is gone. If you match these errors in ignoreErrors or a baseline, they may need updating, and the newly reported usages can add errors.
Your coding agent can read these notes before it upgrades. Set up the MCP server →
New bundled configuration file disallowed-non-timing-safe-calls.neon for code that works with keys, tokens, and other secrets: it disallows hex2bin(),
New bundled configuration file disallowed-non-timing-safe-calls.neon for code that works with keys, tokens, and other secrets: it disallows hex2bin(), bin2hex(), base64_decode(), and base64_encode(), because their runtime depends on the processed bytes and can leak information about them, and recommends the sodium_* functions instead, or ParagonIE\ConstantTime\* when ext-sodium is not available (#433, #434)
includes:
- vendor/spaze/phpstan-disallowed-calls/disallowed-non-timing-safe-calls.neon
Note: comparing secrets, digests, hashes is the other half - use hash_equals(), not ===, which is an operator, so no rule here can catch it.
The lowest supported PHPUnit is now 9.6 so tests run on PHP 7.4 again (#426), and the PHPUnit 13.2 expectExceptionMessage() deprecation is handled whi…
Attributes placed on a method or a function - not just used inside one - now match the name-based allowInMethods/allowInFunctions patterns, the same way allowInMethodsWithAttributes already matched them (#427, #428 - possible BC break)
Allow directives now fall through to the next one in the same config entry when they don't match, so e.g. allowInInstanceOf combined with allowInClassWithAttributes works as alternatives; how the directives compose is now documented (#429, #430)
Documented that directive aliases (allowInFunctions/allowInMethods, disallowInMethods/allowExceptInMethods etc.) refer to one single directive and only one of them is used when an entry sets several (#430)
expectExceptionMessage() deprecation is handled while keeping older PHPUnit versions working (#425)goto is reachable again in the test fixture (#420)Possible BC break note: allowExceptInMethods and its aliases can now report an attribute placed on a matching method or function, which was previously always allowed - if attribute errors newly appear, check your patterns. Other than that, errors can only disappear with this release.
classPattern param directive matches a parameter's declared class name against a wildcard pattern using fnmatch() (#412, docs example #417)
classPattern param directive matches a parameter's declared class name against a wildcard pattern using fnmatch() (#412, docs example #417)allowInInstanceOf/disallowInInstanceOf now support fnmatch() wildcard patterns (#399, docs example #417) and param conditions (#401)allowExceptIn/allowExceptInMethods and their disallowIn* aliases (#414)allowExceptParamsAnywhere and disallowParamsAnywhere aliases for allowExceptParams/disallowParams to match other *Anywhere directives (#410)typeString: descriptive exception on parse failure (#407)typeString now throws an exception, and '0' (a string consisting of 0) is now a valid typeString (#409)func(...)) with param conditions is now handled correctly (#418)allowExceptInFunctions/allowExceptInMethods with multiple entries only checked the first one, not anymore (#405)CLAUDE.md (#403, export-ignored in #413)export-ignore phpstan-dead-code-detector.php from release archives (#413)Applies only to disallowedNamespaces and disallowedClasses, the following configuration keys let you permit (or restrict) a class or namespace based o
Applies only to disallowedNamespaces and disallowedClasses, the following configuration keys let you permit (or restrict) a class or namespace based on whether it appears as a parameter type hint or a return type hint in a function or method signature, and ban (or allow) using it elsewhere, for example in the method body.
allowInParamTypes: trueallowExceptInParamTypes: true (or the disallowInParamTypes alias)allowInReturnType: trueallowExceptInReturnType: true (or the disallowInReturnType alias)See the docs for examples.
Note: to enable usage in use imports use allowInUse: true.
X.Y.Z to eliminate test-runner warnings (#393, thanks @Copilot)allowInMethodsWithAttributes in signatures to use a node visitor (#395)Can disallow (some) keywords with disallowedKeywords, only global supported for now
Can disallow (some) keywords with disallowedKeywords, only global supported for now (#390)
parameters:
disallowedKeywords:
-
keyword: 'global'
allowIn:
- 'legacy/*'
This release includes a proper fix for the "defined in" checks originally fixed in 4.9.1.
This release includes a proper fix for the "defined in" checks originally fixed in 4.9.1. (#388)
As a necessary side effect, unknown functions (functions where their reflection is not available) won't be reported as disallowed anymore, if configured, by this extension as is the case with for example methods already.
Short-cut "defined in" checks for built-in functions and methods (#384) (Now they're not flagged anymore)
Naming is hard, so that's why this _Disallowed Calls_ extension now supports disallowing instance and static properties, and enum properties with disa
Naming is hard, so that's why this Disallowed Calls extension now supports disallowing instance and static properties, and enum properties with disallowProperties (#378)
Generator (#372)include types in the switch (#373)disallowedSuperglobals docs more clear that it doesn't recommend $_REQUEST (#377)Oh, a Friday 13th release! 👻
You can now also pass an array to errorTip in the config:
You can now also pass an array to errorTip in the config:
errorTip:
- Tip 1
- Tip 2
PHPStan will print al the tips, but please note that tips will be prefixed with •, like this:
💡• a tip
• another one
errorTip (#367 #369, thanks @Copilot and myself 🤖)Don't include template types in constant's declaring class display name, needed for PHPStan 2.1.38+
bin (#358)Add a link to a new Symfony config package that has just dd() and dump() for now
dd() and dump() for now (#353)Automate end-to-end tests (#336, #339; _want to add your repo to end-to-end tests, see below? Let me know!_)
phpstan-ignore-errors.php into the package (#328)hasConstant check (#343)A test to ensure the extension still works where it was working before. The test checks out a configured repository, installs the latest version of the extension, then runs PHPStan.
If you disallow multiple classes or namespaces using an fnmatch wildcard, for example like this: `neon disallowedClasses: - class: 'Foo\Bar\*Something
If you disallow multiple classes or namespaces using an fnmatch wildcard, for example like this:
disallowedClasses:
-
class: 'Foo\Bar\*Something'
... then there may be one or more classes that you'd like to exclude from all the *Something classes for some reason. Previously, starting with 2.15.0, you could exclude them by name using the exclude option:
exclude:
- 'Foo\Bar\NotThisSomething'
This release brings a new directive called excludeWithAttribute which you can also use to exclude items from the original set, but based on whether they have the specified attribute:
disallowedClasses:
-
class: 'Foo\Bar\*Something'
excludeWithAttribute:
- 'MyApp\ThisAttribute'
Then if you have two classes like this:
namespace Foo\Bar;
class ThisSomething
{
}
#[\MyApp\ThisAttribute]
class ThatSomething
{
}
then only ThisSomething class would be disallowed.
excludeWithAttribute is supported for classes and namespaces for now, and supports fnmatch patterns.
zend.assertions=1 (#321)This is a follow-up to the `allowInMethodsWithAttributes` feature added in 4.3.1.
This is a follow-up to the allowInMethodsWithAttributes feature added in 4.3.1.
When you disallow the Event class (with disallowedClasses) and would like to allow it again in a method that has the Attr attribute (see the example code below), the Event class should be allowed even in the method signature. Previously, it was flagged as a disallowed usage (#315)
class Handler
{
#[Attr]
public function foo(Event $event) // should be allowed too
{
$event = new Event(); // allowed
}
}
You can now allow some items in instanceofs (allowInInstanceOf, allowExceptInInstanceOf, allowInUse directives, docs)
instanceofs (allowInInstanceOf, allowExceptInInstanceOf, allowInUse directives, docs) (#306)allow* support for all items (previously constants, superglobals and control structures didn't support for example allowInMethods etc.) (#310)If this extension helps you write better code you can sponsor a release or buy me a 🍻 or a 🍰, thanks!
This bugfix release includes a better detection of disallowed attributes reallowed in a method with attributes
This bugfix release includes a better detection of disallowed attributes reallowed in a method with attributes (#304)
The original 4.3.0 release notes:
This release has been sponsored by @ticketswap & @ruudk, thank you 🍰
So far, when you wanted to re-allow a disallowed function or a method, or specifically disallow them, you could use:
allowIn path to specify a path or a filename where the function or method could be called without generating an errorallowInMethods (or the allowInFunctions alias) to specify functions and methods in which the disallowed function would be alloweddisallowIn or disallowInMethods (or the allowExceptIn[...] aliases) if you wanted to list paths or methods in which the call is explicitly disallowedStarting with this release, you can use attributes to sort of mark functions and methods in which the disallowed call would be allowed (or explicitly disallowed):
allowInClassWithAttributes to allow for example a method in a class that has a specified class attributeallowInMethodsWithAttributes (or the disallowInFunctionsWithAttributes alias) to allow the call in methods (or function) with the given method attribute (or a function attribute)allowInClassWithMethodAttributes to allow a call in a class where any method has the attribute, where "any method" includes any other method as well, static or not, public, private, or protecteddisallowIn[...] counterparts (with allowExceptIn[...] aliases) to specify only classes and methods in which the call should be disallowedThis allows you to create rules that do not depend on paths or method names, and can be useful if you're working with frameworks or libs that already use attributes. You can specify multiple items in the directives above and only one of them needs to match (it's not an AND list, more like OR list) and they all support fnmatch patterns.
fnmatch less often only when needed (#297)disallowedAttributes docs (#299, thanks @ruudk)You too can sponsor a release or buy me a 🍻 or a 🍰, thanks!
_This release has been sponsored by @ticketswap & @ruudk, thank you_ 🍰
This release has been sponsored by @ticketswap & @ruudk, thank you 🍰
So far, when you wanted to re-allow a disallowed function or a method, or specifically disallow them, you could use:
allowIn path to specify a path or a filename where the function or method could be called without generating an errorallowInMethods (or the allowInFunctions alias) to specify functions and methods in which the disallowed function would be alloweddisallowIn or disallowInMethods (or the allowExceptIn[...] aliases) if you wanted to list paths or methods in which the call is explicitly disallowedStarting with this release, you can use attributes to sort of mark functions and methods in which the disallowed call would be allowed (or explicitly disallowed):
allowInClassWithAttributes to allow for example a method in a class that has a specified class attributeallowInMethodsWithAttributes (or the disallowInFunctionsWithAttributes alias) to allow the call in methods (or function) with the given method attribute (or a function attribute)allowInClassWithMethodAttributes to allow a call in a class where any method has the attribute, where "any method" includes any other method as well, static or not, public, private, or protecteddisallowIn[...] counterparts (with allowExceptIn[...] aliases) to specify only classes and methods in which the call should be disallowedThis allows you to create rules that do not depend on paths or method names, and can be useful if you're working with frameworks or libs that already use attributes. You can specify multiple items in the directives above and only one of them needs to match (it's not an AND list, more like OR list) and they all support fnmatch patterns.
fnmatch less often only when needed (#297)disallowedAttributes docs (#299, thanks @ruudk)You too can sponsor a release or buy me a 🍻 or a 🍰, thanks!
Check just one callable parameter variant (#293) this fixes a rather rare regression introduced in 4.1.1.
Can disallow isset() in disallowedFunctionCalls (#289, thanks @ksaveras!)
isset() in disallowedFunctionCalls (#289, thanks @ksaveras!)unset, too (#291)array_merge arrays with error messages only when not empty, this should speed things up a bit, maybe (#287)_This version replaces 4.1.0 in which callables were not detected in constructors. The notes below are taken from 4.1.0._
This version replaces 4.1.0 in which callables were not detected in constructors. The notes below are taken from 4.1.0.
This release adds new detections listed below, meaning it's possible that you'll see new error messages.
First class callable syntax (#279), for example:
$func = print_r(...);
Dynamic calls (#276, #278), for example:
$func('foo');
$object->$method();
Test anonymous class usages (#277), for example:
$foo = new class implements ...
$foo = new class extends ...
Anonymous class usages (when the anonymous class extends DisallowedClass for example) were detected before, however the detection is now tested.
Detect callable parameters (#281, #283, #285), for example:
array_map('function', []);
array_map([$object, 'method'], []);
array_map([Class::class, 'staticMethod']);
This release has been replaced by 4.1.1 which also detects callables in constructors, unlike this version.
This release has been replaced by 4.1.1 which also detects callables in constructors, unlike this version.
The 4.0 release removed support for PHPStan 1.x, and this release brings it back. Both PHPStan 1.12 and PHPStan 2.0 are supported (#273).
The 4.0 release removed support for PHPStan 1.x, and this release brings it back. Both PHPStan 1.12 and PHPStan 2.0 are supported (#273).
You can learn more about PHPStan 2.0 in the release notes or in the blog post and don't forget to get yourself an elephpant and a t-shirt!
This major release supports and requires PHPStan 2.0 (#267) (_update_: the 4.0.1 release adds back support for PHPStan 1.12)
This major release supports and requires PHPStan 2.0 (#267) (update: the 4.0.1 release adds back support for PHPStan 1.12)
As mentioned in the UPGRADING.md guide:
It's not feasible to try to support both PHPStan 1.x and PHPStan 2.x with the same extension code.
You can learn more about PHPStan 2.0 in the release notes or in the blog post and don't forget to get yourself an elephpant and a t-shirt!
- Support PHP 8.4 (#270) That's it. That's the release.
That's it. That's the release.
Add phpstan/phpstan-deprecation-rules in expectation of PHPStan 2.0
create_function as a disallowed function call (#261, thanks @BackEndTea)ClassConstFetch where $class is Name only for enums to correctly support PHPStan 1.12.6 (#266)Internal changes:
Add default error identifiers, used if not specified/overridden in your custom config
PHPStan 1.11 added error identifiers and while they were supported by this extension for quite some time (since #97), they were not added by default, only when you've specified them.
This release adds error identifiers everywhere, and they'll be used if you don't specify custom identifiers in your custom config.
The full list of identifiers is in the ErrorIdentifiers class here https://github.com/spaze/phpstan-disallowed-calls/blob/main/src/RuleErrors/ErrorIdentifiers.php and they have a disallowed.something format.
Can disallow control structures like else, elseif, goto
else, elseif, goto (#257)Checking params inside ( ... ) doesn't work at the moment, so you can disallow all declare() constructs but can't re-allow e.g. declare(strict-types = 1).
If you try to disallow else if with the space, an exception will be thrown, because else if is parsed as else followed by if, so disallowing else if with the space wouldn't have the desired effect and the result would be unexpected. Disallow elseif, or don't write else if in your code 😇
https://www.michalspacek.com/stealing-session-ids-with-phpinfo-and-how-to-stop-it
phpinfo() to dangerous calls config (#255)See
for reasons why (phpinfo() echoes cookie values like the session id, which may then be stolen with XSS for example, bypassing HttpOnly cookie flag), and use https://github.com/spaze/phpinfo instead of just calling phpinfo().
array_values() (#253, this is a new bleeding edge rule added in PHPStan 1.10.59)Hardcode ENT_QUOTES as int 3 in disallowed-loose-calls.neon config
ENT_QUOTES as int 3 in disallowed-loose-calls.neon config (#250)Support dynamic class constant fetch available in PHP 8.3 (#242, #248)
disallowedEnums, they use DisallowedConstant internally (#243, docs)disallowedConstants' constant field is always present (#245)The 3.1.0 release was the same minus #248.
Nothing published for this version
New major version because some major new features in this release, and some potential backwards compatibility breaks, if you use the extension in one
New major version because some major new features in this release, and some potential backwards compatibility breaks, if you use the extension in one way or another, all described below.
typeString config option (#234)
You can now specify dis/allowed parameter values as PHPDoc string like typeString: 'foo'|'bar' or typeString: 'array{}' etc. instead of just value: scalarmessage key in the disallowed configuration, "because reasons" was added automatically. I thought it was funny back when this was an internal extension only, but maybe it's not anymore. So there's no "because reasons" anymore, and the error message will always end with a full stop ., unless it already ends with one, or unless it ends with ? or !.allowExceptParamsInAllowed description in docs was flipped around (#235)libs dir into src (#227)ClassWithAttributesAllow (#230)Bump actions/checkout from 3 to 4
Did you know you can use @dependabot to update your actions, not just your code? I've updated my article which mentions Dependabot https://www.michalspacek.com/dont-let-security-bugs-catch-you-off-guard#github-dependabot
So you can disallow Interface::method() and Implementation::method() will also be detected. It already worked for constructors so makes sense to suppo
So you can disallow Interface::method() and Implementation::method() will also be detected. It already worked for constructors so makes sense to support it generally.
#[\Foo()], not just like Foo (#207)Make copy/pasting attribute names more straightforward. Similar already works for method calls etc.
The README file was getting way too big already, making it shorter also gives better overview of what the extension does.
required because I don't trust anyone (=me) to not forget to add that file. Autoloading them seemed fine but the order could be more or less random which could break some tests, and it did.list<type> instead of type[] where possible (#214)Fixes The definedIn filter added in 2.15.0 now also works correctly and as expected for new Class() statements (#203, thanks @BackEndTea)
Fixes
The definedIn filter added in 2.15.0 now also works correctly and as expected for new Class() statements (#203, thanks @BackEndTea)
Internal changes
Handy when you disallow items with wildcards but there's this one thing you'd like to leave out. ```neon parameters: disallowedFunctionCalls: - functi
Handy when you disallow items with wildcards but there's this one thing you'd like to leave out.
parameters:
disallowedFunctionCalls:
-
function: 'pcntl_*()'
exclude:
- 'pcntl_foo*()'
exclude can be a string or an array/list of strings. Currently works for attributes, function & method calls, namespaces.
definedIn?:string|list<string> config option (#198, #200)To further specify/limit files where the function or method should be defined to be disallowed.
parameters:
disallowedFunctionCalls:
-
function: '*'
definedIn:
- 'vendor/foo/bar'
disallowedMethodCalls:
-
method: '*'
definedIn:
- 'vendor/foo/bar'
definedIn can also be string or a list/array of strings. Currently works for function and method calls only. You may also need to set filesRootDir, see the README.
str_starts_with() (#196)Re-allowing disallowed attributes didn't work properly when attributes parameters were involved. This release fixes it (#190, thanks @ruudk)
Re-allowing disallowed attributes didn't work properly when attributes parameters were involved. This release fixes it (#190, thanks @ruudk)
The disallowed attributes feature was added in v2.13.0 and was sponsored by @ruudk @TicketSwap, thank you!
_Release 2.14.0 has introduced a regression (#189) and has been replaced with 2.14.1. Original release notes follow:_
Release 2.14.0 has introduced a regression (#189) and has been replaced with 2.14.1. Original release notes follow:
$foo::BAR where $foo is declared as class-string<Foo>, this partly fixes a very old issue (#186, thanks @eithed)Internal change:
\Name\Space → Name\Space) (#187)_This feature was sponsored by @ruudk @TicketSwap, thank you!_
Can disallow attributes (#183)
This feature was sponsored by @ruudk @TicketSwap, thank you!
Can even re-allow them back with a config similar to re-allowing method calls (with allowIn, allowParamsAnywhereAnyValue, allowInMethods etc.).
This may be most useful in the following cases:
Doctrine\ORM\Mapping\Entity attributes to have repositoryClass specifiedAttributes are available starting with PHP 8.0.
Smaller changes
I've also added a sponsorship button so you can buy me a ☕ or a 🍺 if this extension helps you in any way (#182)
Arrays in param configs (allowParam*, allowExceptParam* etc.) not supported at the moment (#177, #165 thanks @mad-briller)
allowParam*, allowExceptParam* etc.) not supported at the moment (#177, #165 thanks @mad-briller)They never were and now it's official. It means that you can't for example allow a method call when a parameter ($message in the case below) would be an array:
parameters:
disallowedMethodCalls:
-
method: 'Logger::log()'
allowParamsAnywhere:
-
position: 1
name: 'message'
value: ['foo', 'bar']
This would mean that Logger::log() would be allowed only when it would be called like Logger::log(['foo', 'bar']). And allowing that is not supported at the moment, only scalar values may be used in value:. It may change in the future though.
Also some internal changes too tiny to even list here:
{Foo,Bar,Baz}::call() is done in one place only (d598c896bcc05f77e8b270f5a249910680686e65)PHPStan 1.10 has deprecated using instanceof *Type for many Type interface implementations, some of which were also used by this extension. I have ref…
PHPStan 1.10 has deprecated using instanceof *Type for many Type interface implementations, some of which were also used by this extension. I have refactored the code so the instanceof checks are not used.
As a result of this:
There are some other internal changes, too, but that's it.
instanceof *Type #174This release adds better Microsoft Windows support. Some extension functionality ("allow calls in") didn't work properly until now.
This release adds better Microsoft Windows support. Some extension functionality ("allow calls in") didn't work properly until now.
Correctly process non-scalar params like func($property . 'string') which would be marked as disallowed even when they weren't (regression introduced
func($property . 'string') which would be marked as disallowed even when they weren't (regression introduced in 2.11.3) (#167)Support union types in params so you can disallow foo param value and it will be found in param types like 'foo'|'bar'
foo param value and it will be found in param types like 'foo'|'bar' (#163)Internal:
Foo::class) are supported (#161, thanks @ruudk also for the Blade-related chuckle)master to mainYou can now disallow/allow/require params (directives like allowParamsInAllowed, allowParamsAnywhere, docs) that are non-scalar, like callbacks etc.,
You can now disallow/allow/require params (directives like allowParamsInAllowed, allowParamsAnywhere, docs) that are non-scalar, like callbacks etc., previously only scalar types (strings, integers, ...) were accepted (#159, thanks @ruudk!)
Child constructors should be disallowed when parent constructor or an interface constructor is disallowed
Internal change only:
_Note: Named params configuration didn't really work in 2.11.0 (#156), this release fixes it. Please find the original 2.11.0 announcement below_
Note: Named params configuration didn't really work in 2.11.0 (#156), this release fixes it. Please find the original 2.11.0 announcement below
Bit more things this time I even had to use headings. In no particular order:
allowParams* config options, see below, previously only positional params were accepted (#141, thanks @ilazaridis for the inital implementation)disallowed-insecure-calls.neon bundled config file now disallows insecure randomness functions rand(), mt_rand(), lcg_value(), uniqid() (#145, thanks @compwright)disable_functions, disable_classes) and now there's a config generator script in bin/generate-from-disabled.php which will read the PHP config and dump the generated NEON config to STDOUT which you can fine-tune and commit to your repository (#149, loosely based on an idea by @staabm, thanks)Named params are now fully supported, even mixed usage of both positional and named
For example, to allow a function foo(string $message, bool $alert): void when called with $alert = true:
allowParamsAnywhere:
-
position: 2
name: 'alert'
value: true
All keys are optional although I'd definitely recommend adding both position and name. The value key doesn't need to be specified with allowParams*AnyValue.
The old-style shortcusts still work:
allowParamsInAllowed:
1: 'foo'
2: true
But they're not recommended because sometimes, somewhere, you may suddenly use a named parameter and you'd start to see disallowed calls for no apparent reason. Some of the bundled config files still use these shortcuts, so they'll be supported for, I think, ever.
This very same excerpt was also added to the README.
Some functions can be called with flags or bitmasks, for example
json_encode($foo, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT);
Let's say you want to disallow json_encode() except when called with JSON_HEX_APOS (integer 4) flag. In the call above, the value of the second parameter (JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT) is 13 (1 | 4 | 8).
For the extension to be able to "find" the 4 in 13, you need to use the ParamFlags family of config options:
allowParamFlagsInAllowedallowParamFlagsAnywhereallowExceptParamFlagsInAllowed or disallowParamFlagsInAllowedallowExceptParamFlags or disallowParamFlagsThey work like their non-flags Param counterparts except they're looking if specific bits in the mask parameter are set.
The json_encode() example mentioned above would look like the following snippet:
parameters:
disallowedFunctionCalls:
function: 'json_encode'
allowParamFlagsAnywhere:
-
position: 2
value: ::JSON_HEX_APOS
Nothing published for this version
Functions & methods can be disallowed only when called from listed functions & methods
If you need to disallow a method or a function call only when done from a particular method or function, use allowExceptInFunctions (with aliases allowExceptInMethods, disallowInFunctions, disallowInMethods):
parameters:
disallowedMethodCalls:
-
method: 'Controller::redirect()'
message: 'redirect in startup() instead'
allowExceptInMethods:
- Controller\Foo\Bar\*::__construct()
You can now disallow methods, functions, constants, namespaces, classes, superglobals only in specified paths
You can now disallow methods, functions, constants, namespaces, classes, superglobals only in specified paths (#134)
Done with allowExceptIn, disallowIn (which is just an alias of allowExceptIn), this allows to create an inverse of allowIn setup:
parameters:
allowInRootDir: %rootDir%/../../..
disallowedMethodCalls:
-
method: 'PotentiallyDangerous\Logger::log()'
allowExceptIn:
- path/to/some/dir/*.php
This will disallow PotentiallyDangerous\Logger::log() calls in %rootDir%/../../../path/to/some/dir/*.php.
You don't need to use allowInRootDir, it's here just to show that the path specified by the option is also used in this case too ☺️
Support disallowing classes in nullable (?DateTime) & union (DateTime|FooBar|null) & intersection (DateTime&FooBar) types
?DateTime) & union (DateTime|FooBar|null) & intersection (DateTime&FooBar) types (#132)require-dev (#130)_Note: 2.6.0 release contained a regression bug and was quickly removed. This release contains features originally found in 2.6.0 plus some more._
Note: 2.6.0 release contained a regression bug and was quickly removed. This release contains features originally found in 2.6.0 plus some more.
use function foo as bar), the alias is also added to error messages e.g. Calling foo() (as bar()) (#120)errorTip, you can configure a tip that will be displayed with a bulb icon (💡) below the error message (#128)Internal:
Add disallowedClasses as an alias of disallowedNamespaces to make it more straightforward to disallow particular classes
disallowedClasses as an alias of disallowedNamespaces to make it more straightforward to disallow particular classes (#113)new _DisallowedClass_ (#115)If you want to disallow multiple calls, constants, class constants (same-class only), namespaces or variables that share the same message and other co
If you want to disallow multiple calls, constants, class constants (same-class only), namespaces or variables that share the same message and other config keys, you can use a list or an array to specify them all:
parameters:
disallowedFunctionCalls:
-
function:
- 'var_dump()'
- 'print_r()'
message: 'use logger instead'
disallowedConstants:
-
class: 'DateTimeInterface'
constant: ['ISO8601', 'RFC3339', 'W3C']
message: 'use DateTimeInterface::ATOM instead'
(#111)
2.3.0 has added a way to detect and disallow superglobal usage, this release changes the way the detection works: now there's a list of all supergloba
2.3.0 has added a way to detect and disallow superglobal usage, this release changes the way the detection works: now there's a list of all superglobals PHP offers and you can disallow any of them. No changes necessary in your config, this is an internal change to allow for memory optimization in upcoming versions of PHPStan.
2.3.0 has added a way to detect and disallow superglobal usage and now it can be allowed back in traits too (#107, thanks @ruudk for spotting the flaw
2.3.0 has added a way to detect and disallow superglobal usage and now it can be allowed back in traits too (#107, thanks @ruudk for spotting the flaw)
Add disallowedSuperglobals rule to disallow usage of:
Add disallowedSuperglobals rule to disallow usage of:
$_GET$_POST$GLOBALSDone by detecting disallowed variables that are not defined in the current scope (#105, thanks @ekisu!)
Optional root dir config/prefix (allowInRootDir) for all allowIn paths, needed when running PHPStan from a subdir for example
allowInRootDir) for all allowIn paths, needed when running PHPStan from a subdir for example (#102)disallow* aliases to allowExcept* config directives, might be more readable (#104)errorIdentifier in the config, will be more useful in the future, see https://github.com/phpstan/phpstan-src/pull/844 (#97, thanks @ruudk)Bugfix:
allowedIn trait files, if the call is in a trait (#103)Internal changes mostly:
composer test), the -dev suffix has been dropped. I'm probably the only one but you too can run only e.g. composer phpunit when building (and breaking) things (#101)Function names, method names, namespaces are matched irrespective of their case (disallowing print_r will also find print_R calls), while anything els
Function names, method names, namespaces are matched irrespective of their case (disallowing print_r will also find print_R calls), while anything else like constants, file names, paths are not. This is similar to how PHP itself works. (#94)
You can also check your code for case-mismatches in general with PHPStan's strict rules, see example.
One column per quarter.