psalm issues around usage of `global` keyword - PHP
It seems like psalm doesn't properly support the usage of global
to declare a global variable:
https://psalm.dev/r/d23b41c6f3
<?php
$c = 0;
function foo() : void {
global $c;
$c++;
}
foo();
printf("%d", $c);
this sample has two false positives: Inside of foo()
it complains about the increment of $c
to be Unused which isn't true because the printf()
in the global scope does make use of the increment.
It also complains in printf()
because it thinks $c
is mixed, but it can't be.
Asked Oct 16 '21 09:10
pilif
2 Answer:
I found these snippets:
https://psalm.dev/r/d23b41c6f3
<?php
$c = 0;
function foo() : void {
global $c;
$c++;
}
foo();
printf("%d", $c);
Psalm output (using commit c87b19e):
INFO: UnusedVariable - 7:4 - Variable $c is never referenced
INFO: MixedArgument - 11:14 - Argument 2 of printf cannot be mixed, expecting float|int|string
1
Answered Jan 24 '20 at 13:44
psalm-github-bot[bot]
Fixed the unused variable false-positive, the mixed
will stay because global
is dangerous
1
Answered May 10 '21 at 20:51
muglug
Read next
- [Enhancement] Add list of used topics to KafkaConnector statuses - Java strimzi-kafka-operator
- every field in solr index stored as array - Python django-haystack
- Any plans to include table component ? - chakra-ui TypeScript
- tailwind-rn - Vue Native JavaScript
- [Bug] Remote Config: Setting MinimumFetchInternalInMilliseconds does not work as expected - quickstart-unity
- LightGBM [R Package] autoconf.ac OpenMP test ignores LDFLAGS (fix provided). - Cplusplus
- bind EINVAL on valid IPv6 Address (IPv4 works fine!) - JavaScript node
- Nightly builds - logisim-evolution Java