-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[PHP] Use IDL namer in PHP generator #8842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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.
|
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! |
|
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). |
|
don't sweat the labeler -- itll correct as we chew through these. |
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.
aaa7f1f to
95fb8ff
Compare
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:To address this, this PR utilizes the
CASE_INSENSITIVEkeyword 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.