Skip to content

Support shouldPrintRawValue for Scalar\Float_ in PrettyPrinter\Standard (#1109) - #1178

Open
littfed wants to merge 1 commit into
nikic:masterfrom
littfed:feat/float-raw-value
Open

littfed wants to merge 1 commit into
nikic:masterfrom
littfed:feat/float-raw-value

Conversation

@littfed

@littfed littfed commented Oct 7, 2026

Copy link
Copy Markdown

Closes #1109

Description

Extends the shouldPrintRawValue and rawValue attribute handling introduced for Scalar\Int_ in #1127 to Scalar\Float_.

When shouldPrintRawValue is set to true on a Scalar\Float_ node, the pretty printer emits the node's rawValue attribute directly instead of normalizing the representation. This allows preserving numeric separators (e.g. 1_000.5) and custom representations (e.g. scientific notation like 2.4578e12).

Changes

  • lib/PhpParser/PrettyPrinter/Standard.php: Check shouldPrintRawValue in pScalar_Float() and return rawValue if true.
  • doc/component/Pretty_printing.markdown: Update documentation to mention that shouldPrintRawValue and rawValue apply to both Scalar\Int_ and Scalar\Float_.
  • test/PhpParser/PrettyPrinterTest.php:
    • Add test cases covering Scalar\Float_ with numeric separators, scientific notation, and when shouldPrintRawValue is false.
    • Prefix testPrintCustomRawValue with test so PHPUnit runs the data provider cases.

Verification

All 1,948 tests and 2,817 assertions pass cleanly with PHPUnit.

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.

Feature: Add option to PrettyPrinter\Standard to print raw values for Int/Float scalars

1 participant