You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "the-liquid-metal (via GitHub)" <gi...@apache.org> on 2023/06/05 03:51:55 UTC

[GitHub] [netbeans] the-liquid-metal opened a new issue, #6031: [PHP] Invoking undeclared/inaccessible instance method might produce error

the-liquid-metal opened a new issue, #6031:
URL: https://github.com/apache/netbeans/issues/6031

   ### 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
   <?php
   declare(strict_types=1);
   
   class MyStrictClass1 {
       public function fnPublic() {}
       protected function fnProtected() {}
       private function fnPrivate() {}
   
       public function test() {
           $this->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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists