apache / apache/netbeans

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

Open
#6,031 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 ```__call``` magic method in order to handle undeclared/inaccessible instance method.

### How to reproduce

```php
fnPublic(); // OK
$this->fnProtected(); // OK
$this->fnPrivate(); // OK
$this->fnUndefined(); // this statement must display error
}
}

class MyStrictClass2 extends MyStrictClass1 {
public function test() {
$this->fnPublic(); // OK
$this->fnProtected(); // OK
$this->fnPrivate(); // this statement must display error
$this->fnUndefined(); // this statement must display error
}
}

class MyClassWithMagicMethods1 {
public function fnPublic() {}
protected function fnProtected() {}
private function fnPrivate() {}

public function __call($name, $args) {
$this->$name(...$args);
}

public function test() {
$this->fnPublic(); // OK
$this->fnProtected(); // OK
$this->fnPrivate(); // OK
$this->fnUndefined(); // OK
}
}

class MyClassWithMagicMethods2 extends MyClassWithMagicMethods1 {
public function test() {
$this->fnPublic(); // OK
$this->fnProtected(); // OK
$this->fnPrivate(); // OK
$this->fnUndefined(); // OK
}
}

$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

$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->test();
$magic->test();
myFunc($strict, $anno, $magic);
(new MyStrictClass2)->test();
(new MyClassWithMagicMethods2)->test();
```

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

Start by reproducing the reported PHP code in the NetBeans PHP editor, checking calls to public, protected, private, and undefined instance methods both inside and outside the class hierarchy. Done means inaccessible or undeclared calls are reported as errors when no __call method applies, while calls handled by __call are accepted.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.