Skip to content

Conversation

@razvanalex
Copy link
Contributor

This PR refactors the PHP IDL generator to use IdlNamer. This continues the work partially addressed in #7491 (which appears stale).

I noticed that tables using PHP keywords as names (e.g., Bool, String) would yield errors in the generated code because keywords cannot be used as class names in PHP, regardless of casing (see PHP docs). It would complain with an error similar to:

PHP Fatal error:  Cannot use "Bool" as a class name as it is reserved in Bool.php on line 11

To address this, this PR utilizes the CASE_INSENSITIVE keyword check introduced in #8420. I have enabled the option for the PHP generator and added a new test case (tests/php_keyword_test.fbs) to verify that keywords (e.g., Bool) are correctly escaped (e.g., Bool_).

This is a stacked PR on top of #8420.

Most languages are not affected by this change. In PHP, some names such
as Bool cannot be used because it is a reserved keyword for to the bool
data type. The field `keywords_casing` in the configs enables checking
all characters in lowercase against every keyword. This should be safe
as flatbuffers does not allow non-ASCII characters in its grammar.
@jtdavis777
Copy link
Collaborator

Thanks @razvanalex -- I still have these on my list to review and get merged. Doing all this on volunteer time but I'm still eager to keep things rolling forward!

@jtdavis777 jtdavis777 self-requested a review December 10, 2025 14:25
@razvanalex
Copy link
Contributor Author

I really appreciate your time! I'm also doing this in my free time, this is why it took me so long with this PR.

I am still working on finalizing (i.e., specifically with testing and keep rebasing the code) the other three PRs to improve the status for PHP flatbuffers. The only concern I have now is that the changes depend on previous ones (hence stacked PRs), and opening new PRs will falsely trigger the github-action labeler to tag with other languages (such as in this PR).

@jtdavis777
Copy link
Collaborator

don't sweat the labeler -- itll correct as we chew through these.

razvanalex and others added 8 commits December 18, 2025 19:30
This refactors the code from google#8202, specifically the
part related to using the NamerPhp.
Add a test case to verify the PHP code generator's handling of
FlatBuffers type names that conflict with PHP's case-insensitive
reserved keywords.

The previous changes updated `idl_gen_php.cpp` to use `CASE_INSENSITIVE`
keyword checking. This test ensures that when a FlatBuffers schema defines
a type (e.g., `table Bool`) with a name that is a PHP keyword, the generated
PHP code correctly escapes the identifier (e.g., `class Bool_`) to prevent
syntax errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants