pdt
pdt copied to clipboard
No suggestions available for class with ArrayAccess returning object using Square brackets
Describe the bug No suggestions available for class with ArrayAccess returning object using Square brackets
Describe the eclipse environment Eclipse PDT 8.1.0.202307051059
To Reproduce Steps to reproduce the behavior:
- Copy this code
#!/usr/bin/php
<?php
class ArrayNewObject
{
public $prop;
public function __construct($prop)
{
$this->prop = $prop;
}
}
class ArrayNewObjectCollection implements ArrayAccess
{
private $members;
/**
*
* {@inheritdoc}
* @see ArrayAccess::offsetGet()
*/
public function offsetGet(mixed $offset): ?ArrayNewObject
{
if (isset($this->members[$offset])) {
return $this->members[$offset];
} else {
return null;
}
}
public function offsetExists(mixed $offset): bool
{}
public function offsetUnset(mixed $offset): void
{}
public function offsetSet(mixed $offset, mixed $value): void
{
$this->members[$offset] = $value;
}
}
$array_new_collection = new ArrayNewObjectCollection();
$array_new_collection['my_key_1'] = new ArrayNewObject('Hello');
$array_new_collection['my_key_2'] = new ArrayNewObject('World');
echo 'Short array access: ' . $array_new_collection['my_key_1']->prop . " " . $array_new_collection['my_key_2']->prop . PHP_EOL;
echo 'Method array access: ' . $array_new_collection->offsetGet('my_key_1')->prop . " " . $array_new_collection->offsetGet('my_key_2')->prop . PHP_EOL;
//$array_new_collection['my_key_1']->
- Uncomment last line with "$array_new_collection['my_key_1']->"
- Ctrl + Space at the end of this line
- Search for "prop" property
Expected behavior Suggestion: $array_new_collection['my_key_1']->prop
For now PDT not always understand arrayaccess interface. Marking as an enhancement.