Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
litdevel opened this issue Jul 11, 2023 · 1 comment

Comments

@litdevel
Copy link

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 litdevel added the bug label Jul 11, 2023
@zulus zulus added enhancement and removed bug labels Jul 11, 2023
@zulus
Copy link
Member

zulus commented Jul 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants