BetterReflection: Last call for `5.0.0` BC breaks
This is just a placeholder to make sure everyone is aware that 5.0.0 is around the corner: if nobody replies to this issue within a couple days, I will release 5.0.0 from 5.0.x (after attempting to put together some release notes @_@ )
If you need to break BC further, now is the time.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 23 (19 by maintainers)
@ondrejmirtes I’d have some free time on Friday (I know, it’s the 24th), but IMO we should at this point:
Would be a good xmas present 😄
@kukulich I’m fine with removing the monkey patching feature if it isn’t useful. It isn’t the main point of the library indeed, but more of a “look what you can do with this”. 👍
At some point in the future I might make a new library that uses BR to do the monkey patching, just for fun 😁
I agree, release the kraken! 😊
I have 5.0.x integrated in PHPStan and it’s super solid. I’ll be able to release PHPStan with Enums support shortly after thanks to BR, I just need a few finishing touches that I hopefully find the time for during the holidays 😊
Closing here: will focus on writing release notes and finishing up all pending details, but no more BEE SEE BREKS!
Yeah, sure 😃 To rephrase the problem one more time, I need to wrap PhpInternalSourceLocator (with ReflectionSourceStubber) in my own PhpVersionBlacklistSourceLocator (https://github.com/phpstan/phpstan-src/blob/master/src/Reflection/BetterReflection/SourceLocator/PhpVersionBlacklistSourceLocator.php) that calls these extra PhpStormStubsSourceStubber methods so that internal PHP functions from runtime version are not considered defined if they don’t exist in the older PHP version set by the user.
The usefulness is demonstrated in the PHPStan playground: https://phpstan.org/r/656bc0ac-949b-45ef-919c-9365d4ebffac - it always runs on PHP 8.0 but sets different
phpVersionfor its PHPStan config when running analysis. If I didn’t use PhpVersionBlacklistSourceLocator, the linked code snippet wouldn’t report an error on PHP 7.x.It’s not parsing Composer autoloader files, it’s parsing the PHP files in the analysed codebase to look for defined classes, interfaces, traits, enums, functions…
Hi, I’m really enjoying. the 5.0.x. branch. Previously my fork has been based off BR 4.3. Now I successfully based my new fork on top of 5.0.x and established a downgrading process so that it works on PHP 7.1+. PHPStan’s tests and PHPStan-on-PHPStan are now green with the new fork. But there’s a bit more work to be done so a few more bugfixes might be submitted.
This is a list of what it does additionally/differently that might be interesting to the original version:
BetterReflection::populate()method so that I can provide my own instances of services to BR (https://github.com/ondrejmirtes/BetterReflection/commit/ad54d35a6092080c9fc1d58e2fb545a47223bde0) and that the whole reflection is consistent.isPresentClass,isPresentFunctionfor PhpStormStubsSourceStubber (https://github.com/ondrejmirtes/BetterReflection/commit/09fd5c2c2f241710143aadb6a489cca96531f600) - so I can ask which symbols should not be present on the $phpVersion provided to the stubber’s constructor. They return?bool. In case offalsePHPStan reports the symbol as undefined.isBuiltIn()still answers correctly.ReflectionConstant::populateValue()(https://github.com/ondrejmirtes/BetterReflection/commit/2c2f032045004a02c860b0ecdc88544524b75f17) - PHPStan has its own version of AutoloadSourceLocator, which can reflect on constants from an unknown file just based ondefined()returningtrue. I need to provide the constant’s value to BR.CompiledValueallowsresource(https://github.com/ondrejmirtes/BetterReflection/commit/0c3ec4b9d9a500592a8f54da561f5b00defe1424) - people do all sorts of crazy sh*t - https://3v4l.org/hNlDD. Also thanks to this,STDINetc. can be reflected.Fooimplements methodFoo, it still works as a constructor on PHP 8, it’s just deprecated (https://github.com/ondrejmirtes/BetterReflection/commit/6f597e60df0946c1b4f6fa935b352e04f9ce9642)Additional things are not part of my fork, but are commited directly to phpstan-src:
class Fooandfunction bar()defined in a single file,function bar()becomes loaded and defined afterclass Foois autoloaded. This requires me to scan the whole file for all symbols when asked forclass Foo.OptimizedDirectorySourceLocatortakes a page from Composer’s classmap generator for quick scanning of files (https://github.com/phpstan/phpstan-src/blob/8737c3b4690661445338db2a6c31d340a0eac4bd/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php#L189-L243).Let me know if anything from this list is interesting to land in BetterReflection. Thanks.
Ok, I suggest to remove the monkey patching feature 😃