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 undeclared/inaccessible static property #220

Open the-liquid-metal opened 1 year ago

the-liquid-metal commented 1 year ago

Bug Description Missing error on accessing undeclared/inaccessible static property.

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;

class Test45 {
    public static string $publicProp;
    protected static string $protectedProp;
    private static string $privateProp;

    public static function fnStatic() {
        static::$publicProp = "foo";     // OK
        static::$protectedProp = "foo";  // OK
        static::$privateProp = "foo";    // OK
        static::$undefinedProp = "foo";  // this statement must display error

        self::$publicProp = "foo";     // OK
        self::$protectedProp = "foo";  // OK
        self::$privateProp = "foo";    // OK
        self::$undefinedProp = "foo";  // this statement must display error

        echo static::$publicProp;     // OK
        echo static::$protectedProp;  // OK
        echo static::$privateProp;    // OK
        echo static::$undefinedProp;  // this statement must display error

        echo self::$publicProp;     // OK
        echo self::$protectedProp;  // OK
        echo self::$privateProp;    // OK
        echo self::$undefinedProp;  // this statement must display error
    }

    public function fnInstance() {
        static::$publicProp = "foo";     // OK
        static::$protectedProp = "foo";  // OK
        static::$privateProp = "foo";    // OK
        static::$undefinedProp = "foo";  // this statement must display error

        self::$publicProp = "foo";     // OK
        self::$protectedProp = "foo";  // OK
        self::$privateProp = "foo";    // OK
        self::$undefinedProp = "foo";  // this statement must display error

        $this::$publicProp = "foo";     // OK
        $this::$protectedProp = "foo";  // OK
        $this::$privateProp = "foo";    // OK
        $this::$undefinedProp = "foo";  // this statement must display error

        echo static::$publicProp;     // OK
        echo static::$protectedProp;  // OK
        echo static::$privateProp;    // OK
        echo static::$undefinedProp;  // this statement must display error

        echo self::$publicProp;     // OK
        echo self::$protectedProp;  // OK
        echo self::$privateProp;    // OK
        echo self::$undefinedProp;  // this statement must display error

        echo $this::$publicProp;     // OK
        echo $this::$protectedProp;  // OK
        echo $this::$privateProp;    // OK
        echo $this::$undefinedProp;  // this statement must display error
    }
}

class Test45b extends Test45 {
    public static function fnStatic() {
        static::$publicProp = "foo";     // OK
        static::$protectedProp = "foo";  // OK
        static::$privateProp = "foo";    // this statement must display error
        static::$undefinedProp = "foo";  // this statement must display error

        self::$publicProp = "foo";     // OK
        self::$protectedProp = "foo";  // OK
        self::$privateProp = "foo";    // this statement must display error
        self::$undefinedProp = "foo";  // this statement must display error

        echo static::$publicProp;     // OK
        echo static::$protectedProp;  // OK
        echo static::$privateProp;    // this statement must display error
        echo static::$undefinedProp;  // this statement must display error

        echo self::$publicProp;     // OK
        echo self::$protectedProp;  // OK
        echo self::$privateProp;    // this statement must display error
        echo self::$undefinedProp;  // this statement must display error
    }

    public function fnInstance() {
        static::$publicProp = "foo";     // OK
        static::$protectedProp = "foo";  // OK
        static::$privateProp = "foo";    // this statement must display error
        static::$undefinedProp = "foo";  // this statement must display error

        self::$publicProp = "foo";     // OK
        self::$protectedProp = "foo";  // OK
        self::$privateProp = "foo";    // this statement must display error
        self::$undefinedProp = "foo";  // this statement must display error

        $this::$publicProp = "foo";     // OK
        $this::$protectedProp = "foo";  // OK
        $this::$privateProp = "foo";    // this statement must display error
        $this::$undefinedProp = "foo";  // this statement must display error

        echo static::$publicProp;     // OK
        echo static::$protectedProp;  // OK
        echo static::$privateProp;    // this statement must display error
        echo static::$undefinedProp;  // this statement must display error

        echo self::$publicProp;     // OK
        echo self::$protectedProp;  // OK
        echo self::$privateProp;    // this statement must display error
        echo self::$undefinedProp;  // this statement must display error

        echo $this::$publicProp;     // OK
        echo $this::$protectedProp;  // OK
        echo $this::$privateProp;    // this statement must display error
        echo $this::$undefinedProp;  // this statement must display error
    }
}

Test45::$publicProp = "foo";     // OK
Test45::$protectedProp = "foo";  // this statement must display error
Test45::$privateProp = "foo";    // this statement must display error
Test45::$undefinedProp = "foo";  // this statement must display error

echo Test45::$publicProp;     // OK
echo Test45::$protectedProp;  // this statement must display error
echo Test45::$privateProp;    // this statement must display error
echo Test45::$undefinedProp;  // this statement must display error

$ins = new Test45;
$ins::$publicProp = "foo";     // OK
$ins::$protectedProp = "foo";  // this statement must display error
$ins::$privateProp = "foo";    // this statement must display error
$ins::$undefinedProp = "foo";  // this statement must display error

echo $ins::$publicProp;     // OK
echo $ins::$protectedProp;  // this statement must display error
echo $ins::$privateProp;    // this statement must display error
echo $ins::$undefinedProp;  // this statement must display error

function myFunc(Test45 $par) {
    $par::$publicProp = "foo";     // OK
    $par::$protectedProp = "foo";  // this statement must display error
    $par::$privateProp = "foo";    // this statement must display error
    $par::$undefinedProp = "foo";  // this statement must display error

    echo $par::$publicProp;     // OK
    echo $par::$protectedProp;  // this statement must display error
    echo $par::$privateProp;    // this statement must display error
    echo $par::$undefinedProp;  // this statement must display error
}

Test45::fnStatic();
$ins->fnInstance();
myFunc($ins);
Test45b::fnStatic();
(new Test45b)->fnInstance();