Jump to content

Archived

This topic is now archived and is closed to further replies.

Tracekill

Very Idiotic Question

Recommended Posts

Probably a very simple and idiotic question to ask but I'm trying to write a simple practice script to test out heredocs. I have this:

[code]<?php

$var1 = "LIBERTY"
$longstring = <<<ENDSTRING
No person shall be held to answer for a capital,
or otherwise infamous crime,
unless on a presentment or indictment of a Grand Jury,
except in cases arising in the land or naval forces,
or in the Militia,
when in actual service in time of War or public danger;
nor shall any person be subject for the same
offence to be twice put in jeopardy of
life or limb; nor shall be compelled in any
criminal case to be a witness against himself,
nor be deprived of life, $var1, or property,
without due process of law; nor shall private
property be taken for public use, without just
compensation.
ENDSTRING;

echo $longstring;

?>
[/code]

It gives me the error:

[code]syntax error, unexpected T_VARIABLE[/code]

Really sorry for wasting your time with such a simple question but I'm stuck, I thought I had everything right.

Share this post


Link to post
Share on other sites
You have a whitespace before ENDSTRING; ;)
It has to be the absolute ONLY thing on the entire line.

You're not wasting our time and it is not an idiotic question. Everybody makes errors when they try to learn something new, and we are here to help people.

Share this post


Link to post
Share on other sites
Wow thank you for your reply it was both helpful and kind.
I had a feeling that was the problem but my editor wouldn't let me delete the space in front of it so I thought it was fine but that was just due to the fact that it was in debug mode. Anyway cleared out that space but getting the same error:

[code]<?php

$var1 = "LIBERTY"
$longstring = <<<ENDSTRING
No person shall be held to answer for a capital,
or otherwise infamous crime,
unless on a presentment or indictment of a Grand Jury,
except in cases arising in the land or naval forces,
or in the Militia,
when in actual service in time of War or public danger;
nor shall any person be subject for the same
offence to be twice put in jeopardy of
life or limb; nor shall be compelled in any
criminal case to be a witness against himself,
nor be deprived of life, $var1, or property,
without due process of law; nor shall private
property be taken for public use, without just
compensation.
ENDSTRING;

echo $longstring;

?>
[/code]

Share this post


Link to post
Share on other sites
Ahh... you forgot to put a semi-colon after [code]$var1 = "LIBERTY"[/code]

Here is the fixed code: [code]<?php

$longstring = "";
$var1 = "LIBERTY";
$longstring = <<<ENDSTRING
No person shall be held to answer for a capital,
or otherwise infamous crime,
unless on a presentment or indictment of a Grand Jury,
except in cases arising in the land or naval forces,
or in the Militia,
when in actual service in time of War or public danger;
nor shall any person be subject for the same
offence to be twice put in jeopardy of
life or limb; nor shall be compelled in any
criminal case to be a witness against himself,
nor be deprived of life, $var1, or property,
without due process of law; nor shall private
property be taken for public use, without just
compensation.
ENDSTRING;

echo $longstring;

?>[/code]

Share this post


Link to post
Share on other sites
See? It was an idiotic problem. SO sorry to waste your time I should really have checked for that but the error return on the following line threw me off.

Share this post


Link to post
Share on other sites
No, it's just fine. If I thought it was waste of time I would not have replied at all.

Let me instead tell you what the error means:
[quote]syntax error, unexpected T_VARIABLE[/quote] means that there is a syntax error. It found a variable where it expected something else, in this case a semi-colon to end the definition of the variable $var1. :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.