Releases: phpstan/phpstan
0.11.8
Improvements
- Support messages on the
@deprecated
phpDoc tag (#1983), thanks @mglaman! Drupal community will be especially happy about this :)
Bugfixes
- Allow using TestCase from PHAR (2bf4963)
- Fix "Couldn't find constant
__COMPILER_HALT_OFFSET__
" (#2137), thanks @arnaud-lb!
Function signature fixes
- Fix some function signatures (#2138), thanks @villfa!
- Fix return type of
ZipArchive::getStream()
(#2133), thanks @tux-rampage!
0.11.7
Improvements
- Support for phpstan/extension-installer!
- Operator type extension (#2114), thanks @kejwmen! This opens door for PHP extensions that overload operators like
+
or*
. - Validate configurations of
rules
andconditionalTags
neon extensions (080fd29, 5e160d4) - Allow multiple paths per ignore (105e83e)
- Expand
%rootDir%
and%currentWorkingDirectory%
inincludes
section (4edbe7c), #2020 - Detect config files included multiple times (31b8c96)
Bleeding edge
See explanation in previous release notes.
- Validate
parameters
config section (54a125d) - Mixed with subtracted type cannot be accepted in the subtracted type (3d3e183)
Bugfixes
- Removed irrelevant default Nette parameters (6b65c31)
- Scope - support constants defined using the const keyword (63c7d13)
- Nicer handling of config errors (2613b75)
- Fixed coalesce operator - right side is not always processed (50b5941), #2093
ObjectType::hasOffsetValueType()
is maybe at most (aa08ef3), #2093- Fixed unsetting non-constant array key from ConstantArrayType (4dc595c), #2121
- Consistent handling of recursive and nonexistent config files (7346583, 76e733c)
Function signature fixes
- Fix
sodium_crypto_scalarmult_base
signature (#2126), thanks @szepeviktor! - Fix
CachingIterator::current
return type (#2129), thanks @bhaal-nig! Redis::close
returns bool (#2131), thanks @spaze!
0.11.6
Improvements
sprintf()
dynamic return type extension (664215a)- InvalidThrowsPhpDocValueRule: allow
@throws void
phpDoc (#2066), thanks @pepakriz! - Define
$container
variable with DI container forautoload_files
andbootstrap
(4824bba) - PHPStan will always exit immediately when issued SIGINT (Ctrl-C) signal (#2051), thanks @slt!
- Checkstyle error formatter uses more deterministic relative path helper (a80456d), #2019
- Improve InstantiationRule so that it understands expressions with constant strings (#2091), thanks @dmitrydymarchuk!
- Allow phpDoc type hinting local static variables (#2098), thanks @iluuu1994!
ObjectType::setOffsetValueType()
looks intoArrayAccess::offsetSet()
method definition (#1898), thanks @adaamz!
Bleeding edge
See explanation in previous release notes.
- Subtractable types -
mixed
,object
and concrete class objects now understands if their subtype is being subtracted from them. So for example a prior check fornull
onmixed
now makes PHPStan understand that the type does not containnull
anymore. This is especially useful for parent and child classes. See examples.
Bugfixes
- Fix Composer autoloading for phpstan-shim in global Composer installation and Docker image
- Fixed
%rootDir%
in phpstan-shim (f17a5a5) - Fix
array_fill
analysis performance by falling back to ArrayType for large arrays (#2088), thanks @dsech!
* Fixed a couple of problems with anonymous classes (4b52556, 6b9a80e), #1839 - Fix ternary operator with error suppression (#2103), thanks @iluuu1994!
Function signature fixes
- Fix
finfo
return types (#2041), thanks @dmitrydymarchuk! glob
can return false (#2037), thanks @orklah!- Add missing parameter to MongoDB's
ReadPreference
constructor (#2052), thanks @Riimu! - Add missing functions from PHP 7.3 (#2075), thanks @villfa!
- Add
DOMNamedNodeMap::count()
, thanks @villfa!
* Fix "passed by reference arguments" on several methods (#2083), thanks @moufmouf! - Fix
Set::join()
return type (#2077), thanks @enumag! - DOM's
documentElement
can be null (#2089), thanks @frederikbosch! - Fixed
array_replace
/array_replace_recursive
return types (36492d2) ZipArchive::getFromIndex
andZipArchive::getNameIndex
can return false (#2094), thanks @tominventisbe!- Update
imap_thread
signature to return false (#1933), thanks @Slamdunk! - Fixed return type of
XMLWriter::openMemory
(#1862), thanks @SuRaMoN! - Fix signature of
IntlDateFormatter::create()
(#1948), thanks @ADmad! - Fixed signatures of several functions (#2086), thanks @villfa!
0.11.5
Improvements
- Dynamic static method return type extension can be used for constructors (f48b179), #2004
- Early terminating method calls - look through implemented interfaces as well (24ce5a5), #2030
Bleeding edge
See explanation in previous release notes.
- Check missing return in functions, methods, and closures - levels 0 and 3 (b149f8e)
- Check for noops on separate lines - level 4 (a794f43)
- Check for unreachable statement - level 4 (83078fe)
- Various
yield
and generators related checks (c952192, 96c57c6, 83e1163)
Bugfixes
count()
: Added support for 2nd parameter (#2006), thanks @CzechBoy!- Fixed expr in
global
statement (066e606), #2010 - Fixed dead code detection with
isset()
(b43cc2c) - Fix optional parameters for
ldap_control_paged_result()
(#2021), thanks @dontub! - Function
ldap_get_entries()
can return false (#2016), thanks @finwe! - Fixed various bugs in
switch
handling (5157708, effac12), #1939, #2014, #2022 - Fix
is_subclass_of()
type-specifying extension (#1814), #1998, thanks @dmitrydymarchuk!
* Fixopenssl_encrypt
$tag byref parameter (#2029), thanks @iluuu1994!
0.11.4
If you want to see the shape of things to come (rules and other features that will arrive in next major version 0.12), you can include this config file in your project's phpstan.neon
:
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included.
Improvements
- Detect invalid service in
conditionalTags
config section (400acf6)
Bugfixes
- Fixed multiple array_key_exists in
||
(d0da752), #1966 - Fixed
__NAMESPACE__
magic constant value (0d4619b), #1986 - Fixed: Foreach with continue in a branch is not always terminating (9d42bc1), #1972
- Fixed: Marks incremented array key as repeated (ccc4f85), #1845
Function signature fixes
0.11.3
This release comes with a complete rewrite of part of PHPStan's core which is in charge of code interpretation and type inference (NodeScopeResolver). You can check out the rewrite in this PR: #1938
It's released as a minor version because it's fully backwards-compatible with previous version - no custom extensions and rules should break with this release. However, every time a bugfix in PHPStan is made, your CI build can fail because PHPStan simply got smarter and sees more types, or finds an error in your code it should have already found. (New rules are added only in major versions, like 0.10, 0.11, and upcoming 0.12.)
Users are usually happy about this - they get more bugs reported to them for free. But if you don't like the risk of your build failing every time new version of PHPStan is released, use composer.lock
file and run composer update
only manually. If you don't commit composer.lock
for any reason, don't use the ^
or ~
version constraint - instead, lock to a specific version, like this: "phpstan/phpstan": "0.11.3"
.
Bugfixes
- Thanks to the rewrite (#1938), about 35 NodeScopeResolver-related bugs were fixed in total.
- Assignments in conditions are finally supported (753ec78)! This haunted PHPStan users since the beginning. These issues are closed thanks to the fix:
- Fixed array access on string (#1896), thanks @CzechBoy!
- Fixed
array_slice
type loss with non-empty array (1814241), #1919 - Fixed analysing trait use from eval (a308deb), #1923
- Fixed trait in eval with phpDoc (30a5ce4), #1923
- Do not skip the rest of traits from TraitUse if one of them isn't in analysed files (5838040)
- Subclasses of "extra offset classes" are offset accessible too (#1930), thanks @zajca!
- Disallow
$this
in static closures (#1907), thanks @iluuu1994! - Fixed falsey context of array&hasOffset (13cef62), #1942
- Fixed invalid + operation detection for array&hasOffset (b5eeff1), #1942
Improvements
- Implement
filter_var
dynamic return type extension (#1900), thanks @iluuu1994! - Support
==
operator between boolean-able types (2a5f95d) - Basic support for
get_class()
in==
operator (df27a12)
Function signatures fixes
- Fix void return typehint for
Ds\Set::first()
(#1958), thanks @demyan112rv!
0.11.2
Improvements
- Added possibility to override rule error file for some custom edgecase rules (#1863), thanks @lookyman!
- Allow annotations to override properties set in PhpDefectClassReflectionExtension (#1857), thanks @thewilkybarkid!
Bugfixes
- Fix method signature rule for private methods (#1837), thanks @iluuu1994!
- Only inherit phpDoc comments of non-private methods (#1867), thanks @iluuu1994!
- Add missing built-in PHP dynamic constants (#1830), thanks @h4kuna!
- Correct the $ownerDocument property types for DOMDocument/DOMElement (#1859), thanks @duncan3dc!
- Correct union of
array&nonEmpty
andarray()
(6e23192), #1810 - Fixed negative context of
if ($array)
(7334947), #1891, #1825 - Fixed
isset()
result for mixed variable type (8e185a7), #1832, thanks @CzechBoy for the bisecting work :)
Function signatures fixes
- Mark MultipleIterator constructor argument as optional (#1841), thanks @cs278!
- Fixed http_build_query signature (91797bb)
- PDOStatement::fetchColumn() may return NULL (#1886), thanks @morozov!
- Update MongoDB\BSON\UTCDateTime construct hinting (#1858), thanks @aiprogMach!
- SplFileObject::current() can return false (#1844), thanks @orklah!
- Add signature and return type for php-postal functions (#1878), thanks @runciters!
0.11.1
Bugfixes
- Fixed crash when extending classes with methods with multiple overloaded variants (56d6517), #1806
- Fixed crash when analyzing methods inside traits (0539b7f), #1793
- Fixed crash when analysing traits in IncompatibleDefaultParameterTypeRule (1122f87), #1784
- Fixed crash with empty dim fetch (
$foo[]
) in array destructuring (list()
) (4ed1012), #1805 - Fixed accessing
int|null
offset on arrays (dac1ea2) - Fixed internal error in
PhpMethodReflection::isVariadic()
in case of invalid cache (#1818), #1477, thanks @dmitrydymarchuk!
Function signatures fixes
0.11
PHPStan 0.11 has been made possible by LOVOO:
LOVOO: PHPStan is an elementary part of our development workflow. We cannot live without it! Thanks for the great work!
Also, my work on PHPStan is enabled by generous patrons over at Patreon. If PHPStan makes your life easier, consider a contribution, it'll be greatly appreciated!
Check out the article about PHPStan in 2018 and this new release at Medium.com!
Major new features
- Ability to ignore errors by path (#1411, #1619), thanks @josephzidell, @damnedest!
- Check - reporting unreachable conditions on level 4. Previously, only projects with
checkAlwaysTrue*
flags set totrue
(usually with installed strict-rules) found out about always true conditions. With this change, always-true conditions with else branches and ternary operators are reported (186e4e0, e06af0e):
if ($alwaysTrue) {
// ...
} else {
// dead - reported on level 4!
}
- Improved analysis of non-empty arrays (5716b2e, 21309e2, deb70ef) - #336, #165, #1539, #1073, #959, #1505, #1409
- Check (level 3) - validate method signatures against parents and implemented interfaces - forces Liskov substitution principle (#1292), thanks @iluuu1994!
- Check - validation of patterns used in
preg_*
functions on level 0 (#1567), thanks @iluuu1994! - Check (level 2) - string and castable-to-string types in
echo
andprint
statements (#1462), thanks @dmitrydymarchuk! - Check (level 3) - report invalid offset assignments (56be6db) - e.g.
$string['foo'] = 'bar'
leads to an error. - Check (level 2) - invalid comparison between an object and a number (#1582), thanks @jasny!
- Check (level 2) - check default function parameter type against typehint and phpDoc (#1608), thanks @iluuu1994!
- Loaded extensions for known functions in PHP runtime are no longer needed for successful ananlysis (8e6a215)
Improvements
- Implicit
@inheritDoc
from parent classes and interfaces (#1533), thanks @iluuu1994! - Memory consumption improvement - limit amount of cached files for parser (#1673), thanks @damnedest!
- Improved precision of reported lines in some rules (9f7ab5b, eaedf17, 9a2646d)
- Dead branches are not analysed (295c8f2)
- IncompatiblePhpDocTypeRule - detect NeverType in
@param
and@return
(a0e2a76) - IncompatiblePropertyPhpDocTypeRule - check for ErrorType and NeverType in properties (7e66cee)
- Report traits in anonymous function typehints - traits are not valid types (2a96f14)
- Always have a nice progressbar (6b04dca)
- Detect
$var[]
used in read context (#1309), thanks @iluuu1994! - Improved invalid offset access detection (7a630b8)
- Moved reporting of
object
accesses and calls to level 6 (216fb2e) - Moved partially correct types in an encapsed string to level 6 (0470c53)
- Array from
pathinfo
may or may not containextension
key (#1637), thanks @jasny! - Make binary operations aware of strings (#1628), thanks @wata727!
- Collecting error handler to report multiple parse errors at once (7b38a23)
- AppendedArrayItemTypeRule - improved message in case of incompatible callables (c1b8540)
- Report all analysed code exceptions for a node at once (663c6d0)
- Simplified and made array_merge extension faster (002aa73) - #1620
Bugfixes
- Fix
@inheritdoc
for recursive interfaces (#1574), thanks @iluuu1994! - Fixed
UnionType::accepts()
by checking inner type to given type (#1581), thanks @jasny! - Fix inheritdoc issue with traits (#1575), thanks @iluuu1994!
- Fix phpDoc resolution for trait methods in same file as class (#1603), thanks @iluuu1994!
- Fix phpDoc resolving for nested traits (7155f2f) - thanks @iluuu1994!
- ImpossibleCheckTypeHelper: improved union type support in
in_array
function (#1545), thanks @pepakriz! - Fix phpdoc resolving for traits in
PhpClassReflectionExtension
(#1587), thanks @iluuu1994! ImpossibleCheckTypeHelper
: fixed case with mixed$haystackType
(#1592), thanks @pepakriz!- Fixed: Call to function
is_callable()
witharray(object, 'yo')
will always evaluate to false. (e38f882) - #1271 - Fix copy and paste error (#1621), thanks @dereuromark!
- False positive for strict comparison on objects (92c9b2b) - #1625
- Fixed
ConstantArrayType::hasOffsetValueType()
(46f2264) - #1593 - Fixed union of multiple array&callable (bceec5f) - #1615
- ConstantArrayTypeBuilder - quickfix for integer overflow (bb6a250) - #1422
- Fix
HasMethodType
andObjectType::hasMethod()
(#1639), thanks @JanTvrdik! - Unify
HasPropertyType
andObjectType::hasProperty()
with HasMethodType (#1721), thanks @CzechBoy! - Unified hasConstant with hasProperty and hasMethod (24178d1)
- Fix condition filtering in short ternary operator (#1677, fixes #1598, #1355), thanks @lookyman!
- Fixed invoking methods on unions (91aea3a) - #1349, #1529
- Fixed fetching union properties (2ba0f4e)
- Report missing ignored errors in checkstyle format (#1717, fixes #1427), thanks @khaperets!
- Fix error message for incompatible callables (#1719), thanks @dmitrydymarchuk!
- Fix failure to recognise initialize int type (#1718), thanks @dmitrydymarchuk!
- Array incorrectly inferred as string after using
list()
(#1737), thanks @dmitrydymarchuk! - Fix nullable string parameter when the |null is not in phpDoc (4c17a30)
dump-deps
- add literal array dependencies as callables (6261cb4)- Get dynamicConstantNames from configuration to avoid filtering (#1781), thanks @rarila!
- Offset does not exist on array() when incrementing key (#1785, cfb0b43), thanks @dmitrydymarchuk!
Function signatures fixes
- Correct return type for
Redis::delete
, addunlink
alias (#1569), thanks @spaze! openssl_csr_get_subject
returns false on error (#1572), thanks @spaze!- Update imap signatures to
RETURN_FALSE
instructions (#1541), thanks @Slamdunk! - Optional parameters for ldap (#1588), thanks @mamchenkov!
- Fix
ZipArchive::getFromName()
(#1599), thanks @enumag! - Fix
Fix DOMDocument::saveHTML()
(#1596), thanks @enumag! - Fix incorrect "offset" parameter types for
IntlBreakIterator
(#1635), thanks @tominventisbe! parse_url
return type extension (#1198), thanks @CzechBoy!- Some
pspell
functions can return false (#1653), thanks @Stadly! pg_fetch_a*
return also false (#1651), thanks @forrest79!pg_field_type_oid
returns int|false (#1701), thanks @sukei!- Update IMAP functions map to return stdClass instead of object (#1681), thanks @Slamdunk!
* Correct return type for array_slice (#1576, fixes #1566), thanks @thewilkybarkid! - Better handling of
mb_*
function return types (#1688), thanks @dmitrydymarchuk! - Fix: return type of
array_filter($mixed)
(#1691, fixes #1607) hrtime()
support for PHP 7.3 (#1697), thanks @lookyman!- Support encoding aliases for
mb_*
functions (#1699), thanks @dmitrydymarchuk! - Added
key()
dynamic return type extension (#1726), thanks @CzechBoy! - Fix signature of
extract
(#1729), thanks @josephzidell! - Fix signature for
MongoDB\Driver\WriteConcern::__construct
(#1730), thanks @alcaeus! ReflectionClass::getReflectionConstant
can return false (f7d74e3)tmpfile
returns false on error (#1738), thanks @Andrewsville!- Fix
Transliterator::transliterate
andtransliterator_transliterate
signatures (#1748), thanks @Daeroni! - Add the failure return type for
shmop_open()
(#1749), thanks @duncan3dc! - Updating
oci_set_db_operation
signature (#1754), thanks @moufmouf! - Fix signature for
jddayofweek
- 2nd parameter is optional (#1776), thanks @muster-mark! - Fix SNMP function mapping (#1765), thanks @simPod!
- Fix
iconv
return types (#1759), thanks @voku! Serializable::unserialize
has parameter$serialized
of type string (#1782), thanks @CzechBoy!
BC breaks
- Moved UselessCastRule to phpstan-strict-rules (08c3b79)
- CLI option
--errorFormat
superceded by--error-format
(12545ac) - Moved
MockObjectTypeNodeResolverExtension
to phpstan-phpunit extension (338cab7) - Reworded an error message:
Negated boolean <expression> is always false.
(#1200), thanks @sanmai!
BC breaks for extension developers
0.10.8
Backported ConditionalTagsExtension from 0.11-dev (4f82846) - thanks @lookyman
I've done this so that we can disable a rule in https://github.com/Roave/no-floaters by default and still support PHPStan 0.10.x.