phpstan

phpstan

PHP Static Analysis Tool - discover bugs in your code without running it!

Member Since 5 years ago

Experience Points
0
follower
Lessons Completed
0
follow
Best Reply Awards
18
repos
Jun
23
9 hours ago
Activity icon
issue

tspencer244 issue phpstan/phpstan

tspencer244
tspencer244

No errors reported when setting explicit type of function argument as `mixed` with phpVersion set to 70400

Bug report

Using mixed as explicit type with function argument on PHP 7.4 is not reported as an error.

Code snippet that reproduces the problem

https://phpstan.org/r/d86d4cdd-b7ee-4f2b-a5cb-1a0d4ced3bb5

Expected output

Parameter $mixed of anonymous function has invalid typehint type mixed.

Did PHPStan help you today? Did it make you happy in any way?

PHPStan has helped me today to add a lot more clarity and confidence to old PHP code that would otherwise be scary to make changes in :slightly_smiling_face:

It always makes me feel happy to fix all of the errors that PHPStan reports, and to bring new files into our existing PHPStan coverage at the strictest level :slightly_smiling_face:

Jun
22
1 day ago
started
started time in 13 hours ago
Activity icon
issue

dktapps issue comment phpstan/phpstan-src

dktapps
dktapps

apply php configurations when fork child workers

Currently, ProcessHelper only copy command-line arguments of phpstan, but ignore those of php itself. In some cases, the custom configuration for php: --configuration (-c in short), is very usefull.

for example: If a custom php.ini is specified when starting phpstan like: php74 -c my-php.ini analyze --level 0 ...

my-php.ini

extension=yaf yaf.use_namespace = On ...

phpstan creates child workers to analyze, however, it only copies its own the command-line arguments, not those of php itself (-c my-php.ini). In workers, "yaf.use_namespace" could not take effect, the reference to "Yaf\Application" will generate "Yaf\Application not found" error message.

dktapps
dktapps

I'd also find this useful, since PHPStan and JIT don't work so well together on Windows, and it's tiresome to have to disable it in php.ini.

pull request

paulbalandan pull request phpstan/phpstan-src

paulbalandan
paulbalandan

Add `ReflectionUnionType` to function map for PHP8

This adds the ReflectionUnionType class to the function map for PHP 8 and updates the return types of ReflectionParameter::getType and ReflectionFunctionAbstract::getReturnType to add it.

Activity icon
fork

paulbalandan forked phpstan/phpstan-src

⚡ PHPStan's source code. This is where development happens. Check https://github.com/phpstan/phpstan for the distribution repository.
paulbalandan MIT License Updated
fork time in 15 hours ago
started
started time in 16 hours ago
started
started time in 16 hours ago
Activity icon
issue

anthonyryan1 issue phpstan/phpstan

anthonyryan1
anthonyryan1

Unreachable statement false positive after continue (uncommon syntax)

Bug report

When used for HTML templates, PHPStan does not seem to understand foreach > if > continue and believes the endif is unreachable when it is required.

Code snippet that reproduces the problem

https://phpstan.org/r/1aca188b-9cd8-4256-a67a-0875e0bcbc17

Expected output

The endif should not be flagged as unreachable, much as we don't consider a } after a continue unreachable.

Did PHPStan help you today? Did it make you happy in any way?

:heart: PHPStan so far. Looking forward to using it more.

Activity icon
issue

palansher issue comment phpstan/phpstan

palansher
palansher

PHP Error: mkdir(): File exists on line 185

Bug report

Good day! Thank you for the extremely useful tool!

In my logs every day I have hundreds of lines: mkdir(): File exists on line 185 in file phar:///home/vladp/dev/sites/gt-vladp-dev1/vendor/phpstan/phpstan/phpstan.phar/src/Command/CommandHelper.php

How to get off it? phpstan ver: 0.12.90

Also, I will appreciate advice on how to diagnose it deeply.

PS: I have MS VS Code and https://marketplace.visualstudio.com/items?itemName=breezelin.phpstan VS CODE extension that use 'phpstan/phpstan' to check code in the background.

palansher
palansher

It needs to be checked like this because of race conditions.

Understood! Thank you 👍

Activity icon
issue

ondrejmirtes issue phpstan/phpstan

ondrejmirtes
ondrejmirtes

PHP Error: mkdir(): File exists on line 185

Bug report

Good day! Thank you for the extremely useful tool!

In my logs every day I have hundreds of lines: mkdir(): File exists on line 185 in file phar:///home/vladp/dev/sites/gt-vladp-dev1/vendor/phpstan/phpstan/phpstan.phar/src/Command/CommandHelper.php

How to get off it? phpstan ver: 0.12.90

Also, I will appreciate advice on how to diagnose it deeply.

PS: I have MS VS Code and https://marketplace.visualstudio.com/items?itemName=breezelin.phpstan VS CODE extension that use 'phpstan/phpstan' to check code in the background.

Activity icon
issue

ondrejmirtes issue comment phpstan/phpstan

ondrejmirtes
ondrejmirtes

PHP Error: mkdir(): File exists on line 185

Bug report

Good day! Thank you for the extremely useful tool!

In my logs every day I have hundreds of lines: mkdir(): File exists on line 185 in file phar:///home/vladp/dev/sites/gt-vladp-dev1/vendor/phpstan/phpstan/phpstan.phar/src/Command/CommandHelper.php

How to get off it? phpstan ver: 0.12.90

Also, I will appreciate advice on how to diagnose it deeply.

PS: I have MS VS Code and https://marketplace.visualstudio.com/items?itemName=breezelin.phpstan VS CODE extension that use 'phpstan/phpstan' to check code in the background.

ondrejmirtes
ondrejmirtes

It needs to be checked like this because of race conditions.

Activity icon
issue

Micr0mega issue comment phpstan/phpstan

Micr0mega
Micr0mega

`@var` declaration ignored when variable used in loop

Bug report

Since #351 and #3515 have been resolved, it should be possible to properly type hint the $this variable. However, when the usage of $this is used as input for a foreach-loop, its declaration seems to be ignored, resulting in:

Variable $this might not be defined.

Code snippet that reproduces the problem

https://phpstan.org/r/c99d8a7c-f470-4b0f-8f14-0635511e6861

Expected output

No errors!

Note that usage before the foreach (first) makes it reports no error: https://phpstan.org/r/a34fd7ac-870e-4fca-9ed3-272be07bec0f

Micr0mega
Micr0mega

Indeed, that does seem to indicate better where the root problem might be located. Here is a simpler example, without the inline class: https://phpstan.org/r/379fcad4-b289-45ce-b0f1-a9d857a31266

Activity icon
issue

palansher issue comment phpstan/phpstan

palansher
palansher

PHP Error: mkdir(): File exists on line 185

Bug report

Good day! Thank you for the extremely useful tool!

In my logs every day I have hundreds of lines: mkdir(): File exists on line 185 in file phar:///home/vladp/dev/sites/gt-vladp-dev1/vendor/phpstan/phpstan/phpstan.phar/src/Command/CommandHelper.php

How to get off it? phpstan ver: 0.12.90

Also, I will appreciate advice on how to diagnose it deeply.

PS: I have MS VS Code and https://marketplace.visualstudio.com/items?itemName=breezelin.phpstan VS CODE extension that use 'phpstan/phpstan' to check code in the background.

palansher
palansher

Thank you very much!

I will use it for now. But please think about a cleaner solution:

Another option: if you check directory existence in your code before mkdir().

or a similar kind of error preventing checking . Because I and somebody else must catch the same error number in other parts of code.

Activity icon
issue

ondrejmirtes issue comment phpstan/phpstan

ondrejmirtes
ondrejmirtes

PHP Error: mkdir(): File exists on line 185

Bug report

Good day! Thank you for the extremely useful tool!

In my logs every day I have hundreds of lines: mkdir(): File exists on line 185 in file phar:///home/vladp/dev/sites/gt-vladp-dev1/vendor/phpstan/phpstan/phpstan.phar/src/Command/CommandHelper.php

How to get off it? phpstan ver: 0.12.90

Also, I will appreciate advice on how to diagnose it deeply.

PS: I have MS VS Code and https://marketplace.visualstudio.com/items?itemName=breezelin.phpstan VS CODE extension that use 'phpstan/phpstan' to check code in the background.

ondrejmirtes
ondrejmirtes

You need to have this at the beginning of your error handler:

    if (!(error_reporting() & $err_no)) {
        return false; // Silenced
    }

From: https://www.php.net/manual/en/language.operators.errorcontrol.php

Activity icon
issue

palansher issue comment phpstan/phpstan

palansher
palansher

PHP Error: mkdir(): File exists on line 185

Bug report

Good day! Thank you for the extremely useful tool!

In my logs every day I have hundreds of lines: mkdir(): File exists on line 185 in file phar:///home/vladp/dev/sites/gt-vladp-dev1/vendor/phpstan/phpstan/phpstan.phar/src/Command/CommandHelper.php

How to get off it? phpstan ver: 0.12.90

Also, I will appreciate advice on how to diagnose it deeply.

PS: I have MS VS Code and https://marketplace.visualstudio.com/items?itemName=breezelin.phpstan VS CODE extension that use 'phpstan/phpstan' to check code in the background.

palansher
palansher

Hi, I have no idea how the @mkdir() call can issue a warning since it's error-suppressed. I suspect you're using a custom error handler in your app loaded maybe via Composer or in your own bootstrapFiles that causes this.

Yes, Ondrey! I have such Error handler thru 'set_error_handler()'! I really need to have all errors of my code in logs. Possibly I need to suppress this particular error. But I don't know how to do it. I'm really dummy :(

Activity icon
issue

ondrejmirtes issue comment phpstan/phpstan

ondrejmirtes
ondrejmirtes

PHP Error: mkdir(): File exists on line 185

Bug report

Good day! Thank you for the extremely useful tool!

In my logs every day I have hundreds of lines: mkdir(): File exists on line 185 in file phar:///home/vladp/dev/sites/gt-vladp-dev1/vendor/phpstan/phpstan/phpstan.phar/src/Command/CommandHelper.php

How to get off it? phpstan ver: 0.12.90

Also, I will appreciate advice on how to diagnose it deeply.

PS: I have MS VS Code and https://marketplace.visualstudio.com/items?itemName=breezelin.phpstan VS CODE extension that use 'phpstan/phpstan' to check code in the background.

ondrejmirtes
ondrejmirtes

Hi, I have no idea how the @mkdir() call can issue a warning since it's error-suppressed. I suspect you're using a custom error handler in your app loaded maybe via Composer or in your own bootstrapFiles that causes this.

Activity icon
issue

ondrejmirtes issue comment phpstan/phpstan

ondrejmirtes
ondrejmirtes

`@var` declaration ignored when variable used in loop

Bug report

Since #351 and #3515 have been resolved, it should be possible to properly type hint the $this variable. However, when the usage of $this is used as input for a foreach-loop, its declaration seems to be ignored, resulting in:

Variable $this might not be defined.

Code snippet that reproduces the problem

https://phpstan.org/r/c99d8a7c-f470-4b0f-8f14-0635511e6861

Expected output

No errors!

Note that usage before the foreach (first) makes it reports no error: https://phpstan.org/r/a34fd7ac-870e-4fca-9ed3-272be07bec0f

ondrejmirtes
ondrejmirtes

Yeah, on a higher level you'd get: Variable $this in PHPDoc tag @var does not match any variable in the foreach loop: $thing

Activity icon
issue

mergeable[bot] issue comment phpstan/phpstan

mergeable[bot]
mergeable[bot]

PHP Error: mkdir(): File exists on line 185

Bug report

Good day! Thank you for the extremely useful tool!

In my logs every day I have: mkdir(): File exists on line 185 in file phar:///home/vladp/dev/sites/gt-vladp-dev1/vendor/phpstan/phpstan/phpstan.phar/src/Command/CommandHelper.php

How to get off it? phpstan ver: 0.12.90

Also, I will appreciate advice on how to diagnose it deeply.

PS: I have MS VS Code and https://marketplace.visualstudio.com/items?itemName=breezelin.phpstan VS CODE extension that use 'phpstan/phpstan' to check code in the background.

mergeable[bot]
mergeable[bot]

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

Activity icon
issue

palansher issue phpstan/phpstan

palansher
palansher

PHP Error: mkdir(): File exists on line 185

Bug report

Good day! Thank you for the extremely useful tool!

In my logs every day I have: mkdir(): File exists on line 185 in file phar:///home/vladp/dev/sites/gt-vladp-dev1/vendor/phpstan/phpstan/phpstan.phar/src/Command/CommandHelper.php

How to get off it? phpstan ver: 0.12.90

Also, I will appreciate advice on how to diagnose it deeply.

PS: I have MS VS Code and https://marketplace.visualstudio.com/items?itemName=breezelin.phpstan VS CODE extension that use 'phpstan/phpstan' to check code in the background.

Activity icon
issue

Micr0mega issue phpstan/phpstan

Micr0mega
Micr0mega

`@var` declaration ignored when variable used in loop

Bug report

Since #351 and #3515 have been resolved, it should be possible to properly type hint the $this variable. However, when the usage of $this is used as input for a foreach-loop, its declaration seems to be ignored, resulting in:

Variable $this might not be defined.

Code snippet that reproduces the problem

https://phpstan.org/r/c99d8a7c-f470-4b0f-8f14-0635511e6861

Expected output

No errors!

Note that usage before the foreach (first) makes it reports no error: https://phpstan.org/r/a34fd7ac-870e-4fca-9ed3-272be07bec0f

Activity icon
issue

steevanb issue comment phpstan/phpstan

steevanb
steevanb

explode() return type is different with PHP < 8.0 and PHP >= 8.0

As explained in the documentation (https://www.php.net/manual/en/function.explode.php), explode() return false when $separator is an empty string with PHP < 8.0 and throw a ValueError exception in same case with PHP >= 8.0.

Actually phpstan don't allow explode() to return false (it's ok for PHP >= 8.0 but not for PHP < 8.0) :

$foo = explode('', 'foo,bar');
if (is_array($foo)) {}
Call to function is_array() with array<int, string>&nonEmpty will always evaluate to true.

How can I change explode() signature only for PHP < 8.0 to add false as valid return type?

steevanb
steevanb

Ok i understand, thanks!

Activity icon
issue

github-actions[bot] issue comment phpstan/phpstan

github-actions[bot]
github-actions[bot]

Array element types not checked when passed on to another method

Bug report

I have declared array<string, mixed> for a method parameter, and array<string, string> for another method. Passing the parameter directly from the first method to the second method is not save, but PHPStan doesn't report any problem. This must be a bug in PHPStan, as this might actually cause fatal errors in PHP (see code example).

Code snippet that reproduces the problem

https://phpstan.org/r/15e45057-3f8d-4345-8fce-67f7abb1d749

Expected output

PHPStan should detect an issue, but it doesn't.

Did PHPStan help you today? Did it make you happy in any way?

Yes, of course it did! :smile: I am currently improving a legacy project, and PHPStan helped me very much with getting things straight. Having this bug solved would allow me to trust my updated code even more! And not get greeted by runtime fatal errors :smile:

github-actions[bot]
github-actions[bot]

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Activity icon
issue

github-actions[bot] issue comment phpstan/phpstan

github-actions[bot]
github-actions[bot]

Failed type determination in conjunction with break

Bug report

False positives from phpstan. It is failing to understand the type checking that has been done when that logic is wrapped up inside some construct with a break.

This is probably a known issue already, but I thought I'd share these examples since they may aid testing.

Code snippet that reproduces the problem

https://phpstan.org/r/3ab40622-86d3-487d-9f98-c0628553ecab

Expected output

No error messages.

Did PHPStan help you today? Did it make you happy in any way?

Yes.... but I'm still on level 7. Wait until I clear all issues at level 8. Then I'll be euphoric!

github-actions[bot]
github-actions[bot]

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Jun
21
2 days ago
Activity icon
issue

ondrejmirtes issue phpstan/phpstan

ondrejmirtes
ondrejmirtes

explode() return type is different with PHP < 8.0 and PHP >= 8.0

As explained in the documentation (https://www.php.net/manual/en/function.explode.php), explode() return false when $separator is an empty string with PHP < 8.0 and throw a ValueError exception in same case with PHP >= 8.0.

Actually phpstan don't allow explode() to return false (it's ok for PHP >= 8.0 but not for PHP < 8.0) :

$foo = explode('', 'foo,bar');
if (is_array($foo)) {}
Call to function is_array() with array<int, string>&nonEmpty will always evaluate to true.

How can I change explode() signature only for PHP < 8.0 to add false as valid return type?

Activity icon
issue

ondrejmirtes issue comment phpstan/phpstan

ondrejmirtes
ondrejmirtes

explode() return type is different with PHP < 8.0 and PHP >= 8.0

As explained in the documentation (https://www.php.net/manual/en/function.explode.php), explode() return false when $separator is an empty string with PHP < 8.0 and throw a ValueError exception in same case with PHP >= 8.0.

Actually phpstan don't allow explode() to return false (it's ok for PHP >= 8.0 but not for PHP < 8.0) :

$foo = explode('', 'foo,bar');
if (is_array($foo)) {}
Call to function is_array() with array<int, string>&nonEmpty will always evaluate to true.

How can I change explode() signature only for PHP < 8.0 to add false as valid return type?

ondrejmirtes
ondrejmirtes

PHPStan differentiates if you pass in an empty string, a non-empty string or a string that it's not sure about. Maybe it will click for you: https://phpstan.org/r/90c5b728-16cd-4e66-89a6-20591155823c

Activity icon
issue

steevanb issue comment phpstan/phpstan

steevanb
steevanb

explode() return type is different with PHP < 8.0 and PHP >= 8.0

As explained in the documentation (https://www.php.net/manual/en/function.explode.php), explode() return false when $separator is an empty string with PHP < 8.0 and throw a ValueError exception in same case with PHP >= 8.0.

Actually phpstan don't allow explode() to return false (it's ok for PHP >= 8.0 but not for PHP < 8.0) :

$foo = explode('', 'foo,bar');
if (is_array($foo)) {}
Call to function is_array() with array<int, string>&nonEmpty will always evaluate to true.

How can I change explode() signature only for PHP < 8.0 to add false as valid return type?

started
started time in 1 day ago