Jump to content

Very Idiotic Question


Tracekill

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.
Link to comment
https://forums.phpfreaks.com/topic/21561-very-idiotic-question/
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]
Link to comment
https://forums.phpfreaks.com/topic/21561-very-idiotic-question/#findComment-96220
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]
Link to comment
https://forums.phpfreaks.com/topic/21561-very-idiotic-question/#findComment-96222
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. :)
Link to comment
https://forums.phpfreaks.com/topic/21561-very-idiotic-question/#findComment-96226
Share on other sites

Archived

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

×
×
  • Create New...

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.