-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extension_loaded breaks MixedAssignment #6457
Comments
I found these snippets: https://psalm.dev/r/8cfb4b0115<?php
class TestCommand
{
public function execute(): void
{
if (extension_loaded('invalid')) {
}
$referenceDate = $this->getReferenceDate();
echo $referenceDate->format('Ymd');
}
/**
* @return \DateTime
*/
public function getReferenceDate(): \DateTime
{
return new \DateTime();
}
}
|
Can you describe your use case a little? When Psalm encounters a extension_loaded function, it will check its content to see if the extension is loaded in the environment that runs Psalm. If it's not, the flag will help skiping part of the analysis to avoid emitting too much error just because the extension is not there. 'invalid' is not detected so Psalm tries its best. There may be a bug lying here because there is no specific code that Psalm should be afraid of, but I'd like to understand what you need this for before diving into the code for possibly hours :p (Note that if you just need a quick solution, you can do that: https://psalm.dev/r/0fc2dc3293) |
I found these snippets: https://psalm.dev/r/0fc2dc3293<?php
class TestCommand
{
public function execute(): void
{
$invalid = 'invalid';
if (extension_loaded($invalid)) {
}
$referenceDate = $this->getReferenceDate();
echo $referenceDate->format('Ymd');
}
/**
* @return \DateTime
*/
public function getReferenceDate(): \DateTime
{
return new \DateTime();
}
}
|
I am using newrelic extension to name and start/stop a transaction. Something like
Your solution is good. Thank you |
you should maybe consider loading the extension on Psalm's environment. it may be able to find more bugs when the extension is there. I'll close this as it seems a pretty edge case and you're satisfied with the quick solution. If I see another similar issue, we'll think about it more. Thanks for your feedback anyway! |
Just wanted to let you know that I encountered the same or similar issue. I have a PHP file as entry point which does check for NewRelic extension at the beginning, but errors after the extension check are ignored by psalm. Environment: Here is a simplified example of my use case:
<?php
require_once __DIR__ . 'vendor/autoload.php';
if (extension_loaded('newrelic')) {
newrelic_name_transaction('Test');
}
$factory = new Factory();
$factory->createBarz();
<?php
class Factory {
public function createFoo() { }
} Psalm runs and reports no errors even though the factory method doesn't exist. As soon as I extract $extension = 'newrelic';
if (extension_loaded($extension)) { it works, and psalm reports that I tried to reproduce it with psalm.dev but there it reports the issues just fine: https://psalm.dev/r/b3e4a13ad6 Anyway, I'm fine with the solution to extract the |
Hmm could you try reproducing on psalm.dev? This should have been fixed by #10295... |
There was no release since then so it makes sense the issue is still here on 5.15 |
Hello,
https://psalm.dev/r/8cfb4b0115
If you comment if (extension_loaded('invalid')) it will know that $referenceDate is DateTime
The text was updated successfully, but these errors were encountered: