Jump to content


Photo

Very Idiotic Question


  • Please log in to reply
5 replies to this topic

#1 Tracekill

Tracekill
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 21 September 2006 - 06:42 PM

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:

<?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;

 ?>

It gives me the error:

syntax error, unexpected T_VARIABLE

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

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 21 September 2006 - 06:44 PM

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.

#3 Tracekill

Tracekill
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 21 September 2006 - 06:49 PM

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:

<?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;

 ?>


#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 21 September 2006 - 06:53 PM

Ahh... you forgot to put a semi-colon after
$var1 = "LIBERTY"

Here is the fixed 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;

 ?>


#5 Tracekill

Tracekill
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 21 September 2006 - 06:54 PM

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.

#6 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 21 September 2006 - 06:57 PM

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:

syntax error, unexpected T_VARIABLE

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. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users