In my code, the parser tends to analyze interfaces as classes. Here is a minimal example:

  $source = "<?php interface Foo { public function bar(); }\n";
  $reader = new PGPReader($source);

  $reader->buildGrammar();
  drush_print("Interfaces");
  $interfaces = $reader->getInterfaces();
  var_dump(array_map(function ($x) { return $x->data->name; }, $interfaces));

  drush_print('Classes');
  $classes = $reader->getClasses();
  var_dump(array_map(function ($x) { return $x->data->name; }, $classes));

Foo is returned as part of the classes, not the interfaces. Am I misusing the API, or is it a bug ?

CommentFileSizeAuthor
#3 1555180-interfaces-list.patch862 bytessolotandem

Comments

fgm’s picture

Note that, when adding this:

  $class = reset($classes);
  var_dump(token_name($class->data->type));

The type of the class is actually T_INTERFACE, not T_CLASS.

solotandem’s picture

Category: bug » feature

Interfaces and classes are parsed using the same routine. Both are added to the list of classes. The list of interfaces is not populated. I would not classify this as a bug, but rather the current implementation. Given that the interfaces list exists, I should probably use it.

solotandem’s picture

Title: Incorrect interface classification » Implement list of interfaces
Assigned: Unassigned » solotandem
Status: Active » Needs review
StatusFileSize
new862 bytes

Please try this patch and let me know. Thanks.

solotandem’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Needs review » Fixed

Implemented in 7.x-2.x branch.

Consider back port to 1.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.