tags:

views:

538

answers:

6

This produces output page OK

$mystring = "<<<EOT";

Replacing it with the following produces

Parse error: syntax error, unexpected $end in file.php on line 737

$mystring = <<<EOT
   This is some PHP text.
   It is completely free
   I can use "double quotes"
   and 'single quotes',
   plus $variables too, which will
   be properly converted to their values,
   you can even type EOT, as long as it
   is not alone on a line, like this:
EOT;

Any ideas as to what is causing the parser to choke?

I'm using PHP 4.4.7.

It is only on one file that this behaviour happens all others follow the PHP defined functionality.

What I am trying to recitify is what could be possibly wrong in the proceding lines so that the PHP parser shows in this failure.

John

changed file contents to :-

<?php

$mystring = <<<WHATEVER
   This is some PHP text.
WHATEVER;
?>

result =

Parse error: syntax error, unexpected $end in file.php on line 5

Any clues

EDIT

original error was to do with T_ENCAPSED_AND_WHITESPACE this can be caused with jQuery for example "if(x == y){$('#my_image').hide():}" is within the heredoc the bigram "{$ will start the parser looking for php variable for substitution.

EDIT

2 good responses.

1) Ch4m3l3on - "<?php" vs "<?" handling.

2) The Disintegrator - <q>had a similar problem with a stupid program that insisted in putting the BOM in a utf-8 file (ignoring preferences)</q>.

EDIT

1) Replacing all content with a single block didn't fix the problem or give any other pointers.

2) No BOM (Byte Order Mark), pity as this or similar majic characters would have explained all symptoms perfectly.

+1  A: 

What if you try:

$mystring = <<<'EOT'
...
EOT;

(Notice the single quotes around the first EOT)

Sean Bright
A: 

I just copy/pasted that into a file and it ran without errors. (PHP 5.2.8 (cli) (built: Feb 6 2009 12:33:08))

So the problem is likely something near that code, but not something you included in the question.

Either that, or a change in PHP since your version was built.

David Dorward
agreed It is only on one file that this behaviour happens all others follow the PHP defined functionality. what is the choke reason though, no one yet has given me any clues
John Griffiths
Since the code provided runs without errors, the choke reason has something to do with the code you haven't shown us — and we don't own crystal balls.
David Dorward
A: 

make sure that EOT; is really at the begin of the line.

if ($muh="kuh") {
     $foo = <<<EOT
           some text text text
EOT;
}
Andreas Klinger
checked EOT at line start before posting as well as if a space is ok so <<< EOT tested as well as <<<EOT plus no lines between EOT..EOTonly letters between EOT..EOTresult send question to stackoverflow to find out if someone knows what could cause symptomsie <? handling} handling<xxx>..</xxx> handling
John Griffiths
A: 

You probably should check if you have any unclosed curly bracket (or brace, can't remember).

For example:

<?php

while(true) {
    echo "Something\n";

?>

Will produce that error.

Pedro Cunha
+1  A: 

Make sure that there is nothing after the 'WHATEVER;'. Even a space will give a parse error. I would delete the line and retype it, hitting <enter> immediately after typing the semi-colon.

Darren
Irrelevant, heredoc works ok in pasted into other php files, the Question is why is the parser choking on valid heredoc where it correctly parses string assignment.
John Griffiths
Clearly the problem is not with the heredoc declaration. The problem must somewhere else in the script. Like Pedro Cunha said, check for improperly closed curly brackets. Also you might wanna replace any php short tags with the full ones.
Ch4m3l3on
Hi Ch4m3l3on - unfortunatly I cannot up-tick your answer as it is a comment. Please repeat your response as an answer "<?php" vs "<?" so I can up-tick it. Still don't know the answer but will investigate you're idea.
John Griffiths
You can up-vote comments too ;)
Ch4m3l3on