10000 [Translator] flexible heredoc extratec with indentation · Issue #40278 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Translator] flexible heredoc extratec with indentation #40278
Closed
@rmdefi

Description

@rmdefi

Symfony version(s) affected: 5.2.3 (using PHP 7.4.15)

Description
Since PHP 7.3, heredoc (and nowdoc) allow the closing marker to be indented, and the corresponding indentation is stripped from the text.
(this is not very well documented, see https://www.php.net/manual/en/migration73.new-features.php#migration73.new-features.core.heredoc)

The PhpExtractor extract the string as is, without stripping the indendation.

How to reproduce

<?php
// text.php
$tr->trans(<<<EOS
    my
    long
    text
    EOS
);
<?php
//extract.php
require 'vendor/autoload.php';

$catalog=new \Symfony\Component\Translation\MessageCatalogue('en');
$extractor=new \Symfony\Component\Translation\Extractor\PhpExtractor();
$extractor->extract('text.php',$catalog);
var_dump($catalog->all('messages'));

will produce:

array(1) {
  '    my
    long
    text' =>
  string(24) "    my\n    long\n    text"
}

Possible Solution
The value of the T_END_HEREDOC token actually contains the indentation, so it could be compared to the value of the corresponding T_START_HEREDOC token (or just look for leading white spaces) to see if there is indentation to strip.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0