- 20 April 2006
- 22.682
- 1.316
Moin.
Is mir heute begegnet (PHP 5.2.5):
liefert
läuft problemlos durch.
Im Manual hab ich nix gefunden, außer, dass
Auch mit Newline vor dem gesamten Heredoc-Ausdruck
funktioniert es nicht.
Ist das ein Bug in PHP? Darf man das einfach nicht machen und es ist nur nicht dokumentiert? Oder liegts vielleicht an meiner Version - bin nicht 100%ig auf dem aktuellen Stand -?
Is mir heute begegnet (PHP 5.2.5):
PHP:
<?php
$foo = array('index' => <<<FAILS
bar
FAILS;
);
echo $foo['index'];
?>
, hingegenPHP Parse error: syntax error, unexpected ';', expecting ')' in ...foo.php on line 4
PHP:
<?php
$var = <<<SUCCESS
bar
SUCCESS;
$foo = array('index' => $var);
echo $foo['index'];
?>
Im Manual hab ich nix gefunden, außer, dass
Quelle: https://de2.php.net/manual/de/language.types.string.php#language.types.string.syntax.heredocIt is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter (possibly followed by a semicolon) must also be followed by a newline.
Auch mit Newline vor dem gesamten Heredoc-Ausdruck
PHP:
<?php
$foo = array('index' =>
<<<FAILS
bar
FAILS;
);
echo $foo['index'];
?>
Ist das ein Bug in PHP? Darf man das einfach nicht machen und es ist nur nicht dokumentiert? Oder liegts vielleicht an meiner Version - bin nicht 100%ig auf dem aktuellen Stand -?