Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1209

PHP compiler generates syntax error when for enums containing constant "GLOBAL"

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 0.6.1
    • Fix Version/s: None
    • Component/s: PHP - Compiler
    • Labels:
      None

      Description

      Reported on IRC:

      If an interface calls for an enum that defines a constant that's an invalid identifier in PHP (e.g. "GLOBAL") the generated code contains a syntax error.

      Example, from the Hive Metastore Thrift interface:

      enum HiveObjectType {
        GLOBAL = 1,
        DATABASE = 2,
        TABLE = 3,
        PARTITION = 4,
        COLUMN = 5,
      }
      

      Generates the following PHP:

      final class metastore_HiveObjectType {
        const GLOBAL = 1;
        const DATABASE = 2;
        const TABLE = 3;
        const PARTITION = 4;
        const COLUMN = 5;
        static public $__names = array(
          1 => 'GLOBAL',
          2 => 'DATABASE',
          3 => 'TABLE',
          4 => 'PARTITION',
          5 => 'COLUMN',
        );
      }
      

      I suggest we prefix enum constants to avoid this situation, although this would mean the interface didn't match.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              nicktelford Nicholas Telford
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: