0

How to use EOD , heredoc as a string array value?

class W
{
    const ERROR = [ 
    'en'=>'<<<EOD 
    error no: %s. 
    EOD'
    ];

    public function a(){
        $message = sprintf(self::ERROR['en'], '1');
        echo $message;
    }

}
$b = new W;
$b->a();

result in:

<<<EOD 
error no: 1. 
EOD

I need:

error no: 1. 
Cœur
  • 37,241
  • 25
  • 195
  • 267
user6827096
  • 1,186
  • 1
  • 11
  • 26

1 Answers1

2

HEREDOC doesn't take quotes.

    'en' => <<<EOD
error no: %s.
EOD
    ];

Note that there must be no space before the EOD marker, nor must there be anything after it.

If you want multiple array elements like this, you will need to put the comma separating the elements on a separate line.

    'en' => <<<EOD
error no: %s.
EOD
  , 'fr' => <<<EOD
erreur nº: %s.
EOD
    ]
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592