the-liquid-metal opened a new issue, #5071:
URL: https://github.com/apache/netbeans/issues/5071
### Description
This issue is related to #5070.
#5070 is only applied on simple value.
If a statement enconter:
- a function/method with nullable or array union return type,
- or a function/method with nullable or array union argument type,
- or object property with nullable or array union type.
there should be a warning message to prevent error, but this warning can be
supressed by IF-STATEMENT.
### Use case/motivation
```php
<?php
class MyClass {
public ?int $prop1;
public int|float|null $prop2;
public string|array $prop3;
public string|bool $prop4;
}
$inst = new MyClass;
$var1 = $inst->prop1;
$var2 = $inst->prop2;
$var3 = $inst->prop3;
$var4 = $inst->prop4;
if (is_null($var1)) {
$var1[] = 100; // var1 is guarded, warning message is suppressed
$var2[] = 100; // var2 is not guarded, warning message is appeared
$var3[] = 100; // var3 is not guarded, warning message is appeared
$var4[] = 100; // var4 is not array nor null, error message is appeared
}
if (is_array($var1)) {
// var1 is never reach here, warning message is appeared
// warning message is not related with autovivification
$var1[] = 100;
}
if (is_null($var4)) {
// var4 is never reach here, warning message is appeared
// warning message is not related with autovivification
$var4[] = 100;
}
//
-------------------------------------------------------------------------------------
function func1(): ?int {}
function func2(): int|float|null {}
function func3(): string|array {}
function func4(): string|bool {}
$var5 = func1();
$var6 = func2();
$var7 = func3();
$var8 = func4();
// do the same as object properties
//
-------------------------------------------------------------------------------------
function func1 (
?int $arg1,
int|float|null $arg2,
string|array $arg3,
string|bool $arg4,
) {
if (is_null($var1)) {
$arg1[] = 100; // arg1 is guarded, warning message is suppressed
$arg2[] = 100; // arg2 is not guarded, warning message is appeared
$arg3[] = 100; // arg3 is not guarded, warning message is appeared
$arg4[] = 100; // arg4 is not array nor null, error message is
appeared
}
if (is_array($var1)) {
// arg1 is never reach here, warning message is appeared
// warning message is not related with autovivification
$arg1[] = 100;
}
if (is_null($arg4)) {
// arg4 is never reach here, warning message is appeared
// warning message is not related with autovivification
$arg4[] = 100;
}
}
```
### Related issues
_No response_
### Are you willing to submit a pull request?
No
### Code of Conduct
Yes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists