[
https://issues.apache.org/jira/browse/THRIFT-1209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15940552#comment-15940552
]
Paul Brown commented on THRIFT-1209:
------------------------------------
Just ran into this yesterday when we used "PUBLIC" as an enum value.
Nicholas's solution sounds good:
{quote}
I suggest that language-specific IDL compilers specially treat identifiers that
are a reserved word in that language by transforming them somehow, e.g.
prefixing with an underscore as in my original example. This way, we can have a
simple rule for each language: "if an IDL identifier is a PHP reserved word, it
will be prefixed with an underscore" etc.
{quote}
Looks like we could accomplish that while still allowing CountryCodeEnum::AF
(not breaking backward compatibility with ::_AF) by overriding __callStatic?
Here's an example of overriding __callStatic:
https://github.com/myclabs/php-enum/blob/master/src/Enum.php#L177-L185
> PHP compiler generates syntax error when for enums containing constant
> "GLOBAL"
> -------------------------------------------------------------------------------
>
> Key: THRIFT-1209
> URL: https://issues.apache.org/jira/browse/THRIFT-1209
> Project: Thrift
> Issue Type: Bug
> Components: PHP - Compiler
> Affects Versions: 0.6.1
> Reporter: Nicholas Telford
>
> 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:
> {code}
> enum HiveObjectType {
> GLOBAL = 1,
> DATABASE = 2,
> TABLE = 3,
> PARTITION = 4,
> COLUMN = 5,
> }
> {code}
> Generates the following PHP:
> {code}
> 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',
> );
> }
> {code}
> I suggest we prefix enum constants to avoid this situation, although this
> would mean the interface didn't match.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)