Fix and improve exporting in PHP format #1950
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In PHP we have two kind of strings (well, excluding heredoc/nowdoc strings):
'Hi there'
)"Hi there"
)They behave very differently:
\'
and\\
)\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 verbosearray(...)
).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 toFormatJson
, and implemented a newFormatPhp
function that: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.