apache / apache/netbeans

[PHP] Invoking undeclared/inaccessible static method might produce error

Open
#6,032 0 comments 0 reactions 0 assignees View on GitHub
kind:feature needs:triage PHP
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

Classes must declare ```__callStatic``` magic method in order to handle undeclared/inaccessible instance method.

### How to reproduce

```php
$name(...$args);
}

public function fnStatic() {
static::fnPublic(); // OK
static::fnProtected(); // OK
static::fnPrivate(); // OK
static::fnUndefined(); // OK

self::fnPublic(); // OK
self::fnProtected(); // OK
self::fnPrivate(); // OK
self::fnUndefined(); // OK
}

public function fnInstance() {
static::fnPublic(); // OK
static::fnProtected(); // OK
static::fnPrivate(); // OK
static::fnUndefined(); // OK

self::fnPublic(); // OK
self::fnProtected(); // OK
self::fnPrivate(); // OK
self::fnUndefined(); // OK

$this::fnPublic(); // OK
$this::fnProtected(); // OK
$this::fnPrivate(); // OK
$this::fnUndefined(); // OK
}
}

class MyClassWithMagicMethods2 extends MyClassWithMagicMethods1 {
public function fnStatic() {
static::fnPublic(); // OK
static::fnProtected(); // OK
static::fnPrivate(); // OK
static::fnUndefined(); // OK

self::fnPublic(); // OK
self::fnProtected(); // OK
self::fnPrivate(); // OK
self::fnUndefined(); // OK
}

public function fnInstance() {
static::fnPublic(); // OK
static::fnProtected(); // OK
static::fnPrivate(); // OK
static::fnUndefined(); // OK

self::fnPublic(); // OK
self::fnProtected(); // OK
self::fnPrivate(); // OK
self::fnUndefined(); // OK

$this::fnPublic(); // OK
$this::fnProtected(); // OK
$this::fnPrivate(); // OK
$this::fnUndefined(); // OK
}
}

MyStrictClass1::fnPublic(); // OK
MyStrictClass1::fnProtected(); // this statement must display error
MyStrictClass1::fnPrivate(); // this statement must display error
MyStrictClass1::fnUndefined(); // this statement must display error

$strict = new MyStrictClass1;
$strict::fnPublic(); // OK
$strict::fnProtected(); // this statement must display error
$strict::fnPrivate(); // this statement must display error
$strict::fnUndefined(); // this statement must display error

MyClassWithMagicMethods1::fnPublic(); // OK
MyClassWithMagicMethods1::fnProtected(); // OK
MyClassWithMagicMethods1::fnPrivate(); // OK
MyClassWithMagicMethods1::fnUndefined(); // OK

$magic = new MyClassWithMagicMethods1;
$magic::fnPublic(); // OK
$magic::fnProtected(); // OK
$magic::fnPrivate(); // OK
$magic::fnUndefined(); // OK

function myFunc(MyStrictClass1 $strict, MyClassWithMagicMethods1 $magic) {
$strict::fnPublic(); // OK
$strict::fnProtected(); // this statement must display error
$strict::fnPrivate(); // this statement must display error
$strict::fnUndefined(); // this statement must display error

$magic::fnPublic(); // OK
$magic::fnProtected(); // OK
$magic::fnPrivate(); // OK
$magic::fnUndefined(); // OK
}

$strict->fnInstance();
$magic->fnInstance();
myFunc($strict, $magic);
(new MyStrictClass2)->fnInstance();
(new MyClassWithMagicMethods2)->fnInstance();
```

### 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

Open the contributing guide

Research direction

Reproduce the supplied PHP example in Apache NetBeans 18 and compare diagnostics for undeclared or inaccessible static calls with and without __callStatic. No source file or test is identified, so trace the PHP editor analysis from this reproduction. Done means invalid calls consistently produce errors while calls handled by __callStatic remain accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.