Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-6193

Can't use attributes with interface constants and methods

    XMLWordPrintableJSON

Details

    Description

      The following code is valid. However, if we use attributes with interface constants and methods, syntax errors occur.

      Example code:

      <?php
      
      #[I1]
      interface I {
          #[I2(1)] // syntax error occurs
          public const I_CONST = "interface";
          #[I3] // syntax error occurs
          public function method(#[I4] $param1, #[I5(), I6("test")] $param): void; // syntax error occurs
      }
      $refI = new \ReflectionClass(I::class);
      $sourcesI = [
          $refI,
          $refI->getReflectionConstant('I_CONST'),
          $refI->getMethod('method'),
          $refI->getMethod('method')->getParameters()[0],
          $refI->getMethod('method')->getParameters()[1],
      ];
      
      foreach ($sourcesI as $r) {
      	$attr = $r->getAttributes();
      	var_dump(get_class($r), count($attr));
      
          foreach ($attr as $a) {
              var_dump($a->getName(), $a->getArguments());
          }
      
          echo "\n";
      }

      Result:

      string(15) "ReflectionClass"
      int(1)
      string(2) "I1"
      array(0) {
      }

      string(23) "ReflectionClassConstant"
      int(1)
      string(2) "I2"
      array(1)

      {   [0]=>   int(1) }

      string(16) "ReflectionMethod"
      int(1)
      string(2) "I3"
      array(0) {
      }

      string(19) "ReflectionParameter"
      int(1)
      string(2) "I4"
      array(0) {
      }

      string(19) "ReflectionParameter"
      int(2)
      string(2) "I5"
      array(0) {
      }
      string(2) "I6"
      array(1)

      {   [0]=>   string(4) "test" }

      Steps to reproduce:

      1. Create a PHP project
      2. Create a new file
      3. Copy and paste the above example code

      Attachments

        Issue Links

          Activity

            People

              junichi11 Junichi Yamamoto
              junichi11 Junichi Yamamoto
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m