eclipse-pdt / pdt

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

Missing error on accessing property with array syntax other than class which implements ArrayAccess #224

Open the-liquid-metal opened 1 year ago

the-liquid-metal commented 1 year ago

Bug Description Missing error on accessing property with array syntax other than class which implements ArrayAccess.

Eclipse environment Version: 2023-06 (4.28.0) Build id: 20230608-1333 PDT: 8.0.0.202306050832

System

To Reproduce Steps to reproduce the behavior: copy-paste this script to the IDE

<?php
declare(strict_types=1);

namespace ns1\ns2;

use stdClass;
use ArrayAccess;

class Test49 implements ArrayAccess {
    private $container = [];

    public function offsetExists(mixed $offset): bool {
        return isset($this->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 = new Test49;
$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
}