[PHP] Accessing/invoking all trait member not in implementing class scope must produce error
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Apache NetBeans version
Apache NetBeans 18
### What happened
The only place where all trait members can be accessed/invoked is the implementing class. Recent RFCs related to trait invalidates previously allowed behavior.
Reference:
- [Accessing static members on traits](https://wiki.php.net/rfc/deprecations_php_8_1#accessing_static_members_on_traits)
- [Constants in Traits](https://wiki.php.net/rfc/constants_in_traits)
### How to reproduce
```php
propX;
echo $this->propY;
echo $this->propZ;
echo static::funcA("foo");
echo static::funcB("bar");
echo static::funcC("baz");
echo self::funcA("foo");
echo self::funcB("bar");
echo self::funcC("baz");
echo $this::funcA("foo");
echo $this::funcB("bar");
echo $this::funcC("baz");
echo $this->funcX("foo");
echo $this->funcY("bar");
echo $this->funcZ("baz");
$func1A = static::funcA(...);
$func1B = static::funcB(...);
$func1C = static::funcC(...);
$func2A = self::funcA(...);
$func2B = self::funcB(...);
$func2C = self::funcC(...);
$func3A = $this::funcA(...);
$func3B = $this::funcB(...);
$func3C = $this::funcC(...);
$func4X = $this->funcX(...);
$func4Y = $this->funcY(...);
$func4Z = $this->funcZ(...);
var_dump($func1A, $func1B, $func1C, $func2A, $func2B, $func2C);
var_dump($func3A, $func3B, $func3C, $func4X, $func4Y, $func4Z);
}
}
$a = new MyClass;
$a->callAll();
// these statements are error
$t = new MyTrait;
echo MyTrait::CONST_1;
echo MyTrait::CONST_2;
echo MyTrait::CONST_3;
echo $t::CONST_1;
echo $t::CONST_2;
echo $t::CONST_3;
echo MyTrait::$propA;
echo MyTrait::$propB;
echo MyTrait::$propC;
echo $t::$propA;
echo $t::$propB;
echo $t::$propC;
echo $t->propX;
echo $t->propY;
echo $t->propZ;
echo MyTrait::funcA("foo");
echo MyTrait::funcB("bar");
echo MyTrait::funcC("baz");
echo $t::funcA("foo");
echo $t::funcB("bar");
echo $t::funcC("baz");
echo $t->funcX("foo");
echo $t->funcY("bar");
echo $t->funcZ("baz");
$func1A = MyTrait::funcA(...);
$func1B = MyTrait::funcB(...);
$func1C = MyTrait::funcC(...);
$func2A = $t::funcA(...);
$func2B = $t::funcB(...);
$func2C = $t::funcC(...);
$func3X = $t->funcX(...);
$func3Y = $t->funcY(...);
$func3Z = $t->funcZ(...);
var_dump($func1A, $func1B, $func1C, $func2A, $func2B, $func2C, $func3X, $func3Y, $func3Z);
```
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
Windows 10
### JDK
Java: 14.0.1; Java HotSpot(TM) 64-Bit Server VM 14.0.1+7 Runtime: Java(TM) SE Runtime Environment 14.0.1+7
### Apache NetBeans packaging
Apache NetBeans binary zip
### Anything else
_No response_
### Are you willing to submit a pull request?
No
Contributor guide
Research direction
Use the supplied PHP trait reproduction as the behavioral entry point, then locate the NetBeans PHP editor or parser validation for trait-member access. Verify the expected distinction between accesses through the implementing class and accesses through the trait or its instance; done means invalid accesses are reported while valid class-scope accesses remain accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, php
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100