eclipse-pdt / pdt

PHP Development Tools project (PDT)
https://eclipse.org/pdt
Eclipse Public License 2.0
188 stars 46 forks source link

No suggestions available for class with ArrayAccess returning object using Square brackets #246

Open litdevel opened 1 year ago

litdevel commented 1 year ago

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:

  1. 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']->


2. Uncomment last line with "$array_new_collection['my_key_1']->"
3. Ctrl + Space at the end of this line
4. Search for "prop" property

**Expected behavior**
Suggestion: $array_new_collection['my_key_1']->prop
zulus commented 1 year ago

For now PDT not always understand arrayaccess interface. Marking as an enhancement.