Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve exporting in PHP format #1950

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mlocati
Copy link

@mlocati mlocati commented May 10, 2024

In PHP we have two kind of strings (well, excluding heredoc/nowdoc strings):

  • single-quoted strings (eg 'Hi there')
  • double-quoted strings (eg "Hi there")

They behave very differently:

  • single-quoted strings can't contain special character sequences (except \' and \\)
  • double-quoted strings can contain sequences (for example \n), as well as variables (example)

This, for example, implies that we have to "escape" the $ in double quoted strings, otherwise we break the strings (and possibly the execution - example).

Furthermore, since PHP 5.4 (which is 12 years old), PHP supports the compact [...] notation for arrays (instead of the more verbose array(...)).

Finally, accordingly to the PSR-2 (PHP Standard Recommendation # 2), NULL values should be written in lower case (see here).

So, we can't really use the same function to generate JSON and PHP strings.

In this PR I renamed the old FormatPhp function to FormatJson, and implemented a new FormatPhp function that:

  • exports strings in single-quote format, if possible
  • escapes more characters if the double-quote format is used

PS: I don't have Delphi, so I didn't test anything (and it has been 3 decades since the last time I wrote some Pascal code 馃槈) - so please check that everything works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant