That’s why this feature is introduced as experimental and is available only through bleeding edge. Does this make list stop being a list? array_filter does that.Does this preserve a list when it was already a list? array_map does that.Does this create a list out of an array that wasn’t a list before? array_values function does that.We had to go through all of those and decide: What was challenging about this feature is that there’s a lot of ways to manipulate arrays in PHP. Public function doFoo ( array $listOfIntegers ) : void It joins many other advanced types expressible in PHPDocs: /** list $listOfIntegers */ List in PHPStan is an array with sequential integer keys starting at 0 and with no gaps. That’s why it’s useful to narrow it down when we’re sure we only want a single concept like a list. PHP arrays are really powerful, but they represent several computer science concepts in a single data structure, and sometimes it’s difficult to work with that. Learn everything about this new feature in the documentation ». \PHPStan \dumpType ( $object ) // BarService public function foo ( object $object ) : void PHPStan 1.9.0 makes this easier for everyone and makes it possible to describe what’s going on inside the called function and how types are narrowed with custom PHPDoc tags Besides arguments, it also supports narrowing types of properties and returned values from other methods on the same object. It’s always been possible to describe these scenarios scenario by writing custom type-specifying extensions, but that comes with the need to understand the core concepts PHPStan is built on, like the abstract syntax tree and the type system. Public function checkType ( object $object ) : voidĭuring the analysis of the foo() method, PHPStan doesn’t understand that the type of $object was narrowed to BarService because it doesn’t descend to called functions and symbols, it just reads their typehints and PHPDocs. $object -> doSomething ( ) // Call to an undefined method object::doSomething(). Let’s consider a custom type-checking function like this: public function foo ( object $object ) : void This feature was developed by Richard van Velzen.Īfter generics and conditional return types PHPStan continues to democratize its advanced features. I acknowledged this in a recent letter to contributors which is well worth your read even if you don’t contribute code yourself.Īt the current rate of quality pull requests from and I might just rename my job title to "green button pusher".- Ondřej Mirtes OctoPHPDoc asserts # My role has shifted from the main code contributor to quality assurance, project vision, and taking care of the continous integration pipeline. I’m now pressing the green “merge” button multiple times a day. It’s not that I don’t like writing code anymore, but others get around to implementing new features faster while I’m down in the weeds hunting mysterious bugs. You’ll notice that every headlining feature of this release has been contributed by someone other than me, the maintainer. PHPStan 1.9.0 has been a real community effort. Menu PHPStan 1.9.0 With PHPDoc Asserts, List Type, and More!
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |