pdt icon indicating copy to clipboard operation
pdt copied to clipboard

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

Open litdevel opened this issue 2 years ago • 1 comments

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']->
  1. Uncomment last line with "$array_new_collection['my_key_1']->"
  2. Ctrl + Space at the end of this line
  3. Search for "prop" property

Expected behavior Suggestion: $array_new_collection['my_key_1']->prop

litdevel avatar Jul 11 '23 12:07 litdevel

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

zulus avatar Jul 11 '23 12:07 zulus