[
https://issues.apache.org/jira/browse/THRIFT-1209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18083626#comment-18083626
]
Volodymyr Panivko commented on THRIFT-1209:
-------------------------------------------
Resolved by THRIFT-5956 (bump minimum PHP version to 8.1). PHP 7.1+ permits
reserved identifiers (except `class`) as class constants, so `public const
GLOBAL = 1;` now parses cleanly whether the surrounding class is namespaced or
sits in the global scope — both forms can still come out of the generator,
depending on whether the IDL declares `namespace php X` (see `emit_file_header`
at `compiler/cpp/src/thrift/generate/t_php_generator.cc:579`).
Verified on current `master` (a2eb3905c): an IDL containing `enum
HiveObjectType { GLOBAL = 1, DATABASE = 2, TABLE = 3, ... }` generates valid
PHP in either case. The original example shape — `final class
metastore_HiveObjectType` (legacy prefix-as-name, no namespace) — is no longer
produced; today's output is either `namespace metastore; final class
HiveObjectType` (when the IDL has `namespace php metastore`) or a global-scoped
`final class HiveObjectType` (when it does not).
The original suggestion to prefix enum constant identifiers is therefore
unnecessary. Suggest closing as Fixed.
> 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
> Priority: Major
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> 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
(v8.20.10#820010)