[PHP] Accessing property with array syntax other than class which implements ArrayAccess 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
Accessing property with array syntax other than class which implements ArrayAccess must produce error.
### How to reproduce
```php
container[$offset]);
}
public function offsetGet(mixed $offset): mixed {
return $this->container[$offset] ?? null;
}
public function offsetSet(mixed $offset, mixed $value): void {
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->container[$offset] = $value;
}
}
public function offsetUnset(mixed $offset): void {
unset($this->container[$offset]);
}
}
$a = MyArrayAccess;
$a[] = "foo"; // OK
$a["bar"] = "baz"; // OK
echo $a["bar"]; // OK
$b = new stdClass;
$b[] = "foo"; // this statement must display error
$b["bar"] = "baz"; // this statement must display error
echo $b["bar"]; // this statement must display error
// ----------------------------------------------------------------------------
function test(ArrayAccess $argArrayAccess, object $argObject) {
$argArrayAccess[] = "foo"; // OK
$argArrayAccess["bar"] = "baz"; // OK
echo $argArrayAccess["bar"]; // OK
$argObject[] = "foo"; // this statement must display error
$argObject["bar"] = "baz"; // this statement must display error
echo $argObject["bar"]; // this statement must display error
}
```
### 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
Start by reproducing the PHP sample in Apache NetBeans 18, focusing on the PHP editor's diagnostics for array syntax. Confirm that ArrayAccess usages remain valid while array access on stdClass and object-typed values produces errors, including reads and writes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100