{{ summaryTitle }}
{{ summaryValue }}

{{ summaryLine }}

Target {{ resultsReady ? `PHP ${computation.normalizedInputs.php_version}` : '—' }} Source mode {{ resultsReady ? sourceModeSummary : '—' }} Privacy Local only
{{ summaryAnnouncement }}
PHP source and formatting controls
The selected runtime drives bounded checks for PHP 8.4 and 8.5 syntax.
Both profiles preserve strings, comments, names, literals, and operators as inert source tokens.
Auto detect reports the requested and resolved mode in the summary and formatting ledger.
Paste, drop, or browse one PHP, PHTML, INC, PHPS, or TXT file up to 250 KB.
{{ sourceMeta }}
{{ fileStatus }}

{{ workflowFeedback }}

The neutral default is Unix LF; merely opening Advanced does not change the artifact.
{{ textExportStatus }}
{{ computation.values.formatted_php }}
{{ chartExportStatus }}

The chart renderer is unavailable. Exact counts remain available in the formatting ledger.

{{ textExportStatus }}
{{ note.title }}

{{ note.detail }}

{{ ledgerExportStatus }}
SignalValueMeaningCopy
{{ row.label }}{{ row.value }}{{ row.detail }}

PHP source often mixes three concerns that need separate review: whether the language version understands the syntax, whether the file is pure PHP or a template with surrounding HTML, and whether its layout follows the project's coding style. A formatter can make the third concern easier to inspect while offering limited help with the first two.

Consistent spacing and indentation reduce friction in code review. Blocks, declarations, operators, comments, and long argument lists become easier to follow, while stable line endings prevent platform-only diffs. For templates, preserving text outside PHP regions is just as important as arranging the PHP inside them.

  • Language target identifies the PHP release the source is expected to run on. New operators and property syntax can make older targets unsuitable.
  • Source mode distinguishes a standalone PHP file from a mixed PHP and HTML template.
  • Style profile controls presentation. It cannot prove that every rule in a broad coding standard has been satisfied.
  • Line endings choose Unix LF or Windows CRLF for the returned text.

Formatting should preserve strings, comments, identifiers, literals, operators, and non-PHP template text as inert source content. It should not rename symbols, reorder imports, rewrite application logic, or execute the code. Those boundaries matter when the result will be reviewed but not immediately run.

A readable result can still fail in production because of a type error, missing extension, autoloading problem, runtime configuration, unsupported library, or code path that the formatter never evaluates. Use the target PHP runtime, static analysis, project tests, and a real template render for final confidence.

How to Use This Tool:

Match the destination runtime and file type before choosing a visual profile.

  1. Select the intended Target PHP version from PHP 8.2 through 8.5. Choose the version that will actually execute the file, not simply the newest option.
  2. Choose Auto detect when the file type is uncertain, Standalone PHP for PHP-only source, or Mixed PHP + HTML template when text surrounds PHP regions.
  3. Use PER Coding Style 3.0 for four-space, declaration-oriented layout or Compact review for a denser two-space result. Select LF or CRLF under Line endings.
  4. Paste or load the PHP source. Correct the first reported line and column when a string, comment, heredoc, delimiter, source-mode choice, or bounded version check blocks formatting.
  5. Compare Formatted PHP with the validation notes and formatting ledger. Then run a syntax check and the project test suite under the selected runtime before replacing the original.

Interpreting Results:

The formatted line count and character delta describe the new layout, not the quality of the code. A larger result normally reflects indentation and blank lines. The PHP-region and template-character counts help confirm that the chosen source mode matches the file.

Read Validation notes before copying. They state the requested and resolved source mode, the selected language target and profile, and the formatter's preservation boundary. A successful result means the lexical transform completed; it is not the same as a clean php -l run.

For a mixed template, compare the surrounding HTML and text as well as the PHP blocks. For a standalone file, unexpected template characters are an error rather than content to preserve.

Technical Details:

A lexical formatter divides source into protected tokens and structural punctuation before changing whitespace. Strings, line and block comments, heredoc and nowdoc bodies, variables, words, numbers, and multi-character operators stay distinct so their contents are not reformatted as ordinary code.

Transformation Core:

PHP lexical formatting transformation stages
Stage Rule Evidence returned
Document partition Recognized <?php and <?= regions are separated from surrounding template text. Resolved source mode, PHP-region count, and preserved template-character count.
Lexical scan Protected text and operators are read while parentheses, brackets, and braces are balanced. A line-and-column issue for an unclosed string, comment, heredoc, or delimiter.
Version gate A small declared set of PHP 8.4 and 8.5 constructs is compared with the selected target. The first recognized target mismatch, if one exists.
Style render Blocks, declarations, operators, commas, comments, and statement breaks receive profile-specific spacing and indentation. Formatted token, line, and character counts.
Line-ending pass The internal LF result is returned as LF or converted to CRLF. A final artifact ending with the selected newline sequence.

Rule Core:

The target check is deliberately bounded. It catches the following recognized version boundaries before the style render begins.

Recognized PHP target-version checks
Construct Minimum target Check performed
Pipe operator |> PHP 8.5 The operator is rejected for PHP 8.2 through 8.4.
Clone-with form clone(...) PHP 8.5 A recognized clone followed by parentheses is rejected for older targets.
Asymmetric set visibility such as private(set) PHP 8.4 A visibility word followed by the recognized setter form is rejected for PHP 8.2 or 8.3.
Recognized property-hook form PHP 8.4 The bounded variable-and-brace pattern is rejected for PHP 8.2 or 8.3.

The PER profile uses four-space indentation and moves recognized declaration braces onto the following line. The compact profile uses two spaces and keeps those braces with their declarations. Both profiles normalize operator spacing and statement layout, but neither claims exhaustive conformance with every PER Coding Style 3.0 rule.

Source text is limited to 120,000 characters, while a loaded file is limited to 250,000 bytes. Character and byte limits differ for non-ASCII source, so a file can reach one boundary before the other.

Limitations:

The formatter does not use the complete parser from the selected PHP runtime. It recognizes enough lexical structure for the declared transform and a small set of recent-version checks, so other invalid or version-specific syntax may still format.

  • Run php -l with the actual CLI or web runtime that will execute the file.
  • Do not treat the PER profile as a full coding-standard audit; use the project's configured style checker for that claim.
  • Strings, comments, symbols, literals, operators, and template text are kept inert, but application behavior still needs tests.
  • Imports are not sorted, names are not changed, and semantic refactoring is not attempted.

References: