[PHP] Counting variable member other than array or Countable must produce error
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Apache NetBeans version
Apache NetBeans 18
### What happened
Counting variable member other than array or Countable must produce error.
### How to reproduce
```php
propObject = new stdClass;
$this->propClosure = fn($a) => $a*10;
$this->propCallable = [self::class, "statFunc"];
$this->propCountable = new MyCountable;
}
}
function returnArray(): array {
return [];
}
function returnNull(): null{
return null;
}
function returnInt(): int {
return 10;
}
function returnFloat(): float{
return 20.34;
}
function returnBool(): bool {
return false;
}
function returnString(): bool {
return false;
}
function returnObject(): object {
return new MyClass;
}
function returnClosure(): closure {
return fn($a) => $a;
}
function returnCallable(): callable {
return [MyClass::class, "statFunc"];
}
function returnCountable(): Countable {
return new MyCountable;
}
$myInst = new MyClass;
// --- array value ------------------------------------------------------------
$var1a = [1,2,3];
count($var1a); // OK
$var1b = returnArray();
count($var1b); // OK
$var1c = $myInst->propArray;
count($var1c); // OK
// --- null value -------------------------------------------------------------
$var2a = null;
count($var2a); // this statement must display error
$var2b = returnNull();
count($var2b); // this statement must display error
$var2c = $myInst->propNull;
count($var2c); // this statement must display error
// --- undefined variable -----------------------------------------------------
count($var3a); // this statement must display error
// --- boolean value ----------------------------------------------------------
$var4a = false;
count($var4a); // this statement must display error
$var4b = returnBool();
count($var4b); // this statement must display error
$var4c = $myInst->propBool;
count($var4c); // this statement must display error
// --- int value --------------------------------------------------------------
$var5a = 10;
count($var5a); // this statement must display error
$var5b = returnInt();
count($var5b); // this statement must display error
$var5c = $myInst->propInt;
count($var5c); // this statement must display error
// --- float value ------------------------------------------------------------
$var6a = 20.34;
count($var6a); // this statement must display error
$var6b = returnFloat();
count($var6b); // this statement must display error
$var6c = $myInst->propFloat;
count($var6c); // this statement must display error
// --- string value -----------------------------------------------------------
$var7a = "Hello";
count($var7a); // this statement must display error
$var7b = returnString();
count($var7b); // this statement must display error
$var7c = $myInst->propString;
count($var7c); // this statement must display error
// --- object value -----------------------------------------------------------
$var8a = new MyClass;
count($var8a); // this statement must display error
$var8b = returnObject();
count($var8b); // this statement must display error
$var8c = $myInst->propObject;
count($var8c); // this statement must display error
// --- closure value ----------------------------------------------------------
$var9a = fn($a) => $a*10;
count($var9a); // this statement must display error
$var9b = returnClosure();
count($var9b); // this statement must display error
$var9c = $myInst->propClosure;
count($var9c); // this statement must display error
// --- callable value ---------------------------------------------------------
$var10a = returnCallable();
count($var10a); // this statement must display error
$var10b = $myInst->propCallable;
count($var10b); // this statement must display error
// --- closure value ----------------------------------------------------------
$var11a = new MyCountable;
count($var11a); // OK
$var11b = returnCountable();
count($var11b); // OK
$var11c = $myInst->propCountable;
count($var11c); // OK
// ----------------------------------------------------------------------------
function test(
array $argArray,
null $argNull,
int $argInt,
float $argFloat,
bool $argBool,
string $argString,
object $argObject,
closure $argClosure,
callable $argCallable,
Countable $argCountable,
) {
count($argArray); // OK
count($argNull); // this statement must display error
count($argInt); // this statement must display error
count($argFloat); // this statement must display error
count($argBool); // this statement must display error
count($argString); // this statement must display error
count($argObject); // this statement must display error
count($argClosure); // this statement must display error
count($argCallable); // this statement must display error
count($argCountable); // OK
}
```
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
Windows 10
### JDK
Java: 14.0.1; Java HotSpot(TM) 64-Bit Server VM 14.0.1+7 Runtime: Java(TM) SE Runtime Environment 14.0.1+7
### Apache NetBeans packaging
Apache NetBeans binary zip
### Anything else
_No response_
### Are you willing to submit a pull request?
No
Contributor guide
Research direction
Use the PHP reproduction in this issue as the starting test, focusing on the count() calls for arrays, Countable values, and other types. Locate the NetBeans PHP analysis entry point that reports countability errors, then verify diagnostics for each shown value category and confirm that arrays and Countable objects remain valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100