A T_STRING is just internal code for a set of characters, like ‘hello
world’. I usually see this particular error if I have been
concatenating two things together and leave out the dot in between.
Here’s a test case that will throw this particular error every time:
<?php echo 'foo' . 'bar' 'baz'; ?>
and this one will not:
<?php echo 'foo' . 'bar' . 'baz'; ?>
PHP is usually ridiculously accurate when it comes to line numbers.
Note that it’s looking for line number 516 in shop.php in your web
root. Open that file and look to that line.
Also, line number can be thrown off by line endings. These are
invisible characters that indicate when a line has been ended and a
new line begins. Good programming editors will sort this out for you
if you open a file containing “mixed” line endings and save it again.
If you’re editing your PHP in Freeway, then you might have such a
mixed-ending situation, because you can set the line endings in
Freeway independently of how you set them in your text editor. A
classic example of this is when you see that your error is on line
number 1 (which is usually just <?php – no error possible there).
What that means is that your code is set for Mac line endings, which
PHP interprets as “one really long line of code”.
Walter
On Jul 27, 2010, at 11:07 AM, hugh wrote:
Hi all,
I’ve just opened a file with lots of table rows in it and changed a
link in one of the rows and altered some minor text.
When I published and uploaded, the new file just gets an error…
Parse error: syntax error, unexpected T_STRING in /web/sites/_c/_o/
_n/conformance.co.uk/public/www/shop.php on line 516
What is a T-string when it’s at home?
There doesn’t seem to be anything amiss with line 516 when I view it
in Smultron - of course this may not be the true line 516…?
This is lines 513 to 519 in the file as downloaded from the web root…
</form>';
}else{
print ‘’;
}
?>
so line 516 is a ’ } '…!!!
What’s wrong with that?
This is a mainly tabled Freeway page which is given a php suffix and has worked quite happily in the past. All I did today was alter some text and a link…nowhere near line 516 apparently!
Hi Hugh,
It’s worth checking the source code for the page in a text editor that
shows you invisible characters. I use BBEdit or Text Wrangler to do
this as it’s all too easy to copy something from a web page an not
realize that the sample code contains numerous characters that the
server will complain bitterly about.
Regards,
Tim.
On 27 Jul 2010, at 16:34, hugh wrote:
This is lines 513 to 519 in the file as downloaded from the web
root…
</form>';
}else{
print ‘’;
}
?>
so line 516 is a ’ } '…!!!
What’s wrong with that?
This is a mainly tabled Freeway page which is given a php suffix and
has worked quite happily in the past. All I did today was alter some
text and a link…nowhere near line 516 apparently!
If I look at the source code of this live web page, all I get is the source code for the error message…
So I’m downloading the shop.php page which was earlier uploaded to the web site. This is the file which is on the web server and is obviously causing the problem - so I’ve downloaded it from site.
I haven’t got BBEdit or Text Wrangler, just Text Edit and Smultron.
Why has it suddenly thrown a fit over minor changes which are nowhere near line 516?..!!!
Check to make sure you’re not using curly-quotes anywhere. If you copied from a Web page like this one (which uses SmartyPants for proper typographical niceties) then you might pick one up without noticing.
Could you please open the published page from Freeway in Smultron or
TextWrangler, and copy everything and paste it over at Pastie.org.
Then post the link here. My guess is yes, something is going wrong in
Freeway, since you haven’t changed shop.php. It’s probably a line of
code that hasn’t been properly terminated or something like that.
Walter
On Jul 27, 2010, at 11:58 AM, hugh wrote:
curly quotes?..??
line 516 is just a }
is that a curly quote?..they’re everywhere!!
downloaded Text Wrangler and it doesn’t look a jot different than in
Smultron.
Remember, I’m not hand editing the shop.php file - I’m just doing
some tweaks in Freeway and republishing. Is Freeway throwing out bum
code?
ps. line 516 now seems to be some code - don’t know why it’s changed from the ‘}’
And the code seems to be related to the if/else code you did for me…if you recall, allowing a dated item to 'degrade to a finished button rather than an active button.
What’s wrong with this is that you are using single-quotes inside of an outer pair of single-quotes. On line 4, you start off with print ' (the opening single-quote), which you intend to have “close” on line 8 with ';. Everything in between is one large variable. But on line 5, you use single-quotes in your HTML (legal, but not common) to enclose the values of your hidden form elements. The first one of those effectively ends the variable you began on line 4, but then you start off again with another single-quote – but without any sort of logical operator or line-ending between them, so PHP blows a gasket.
When you are “inside” a pair of quotes, either single- or double-quotes, you cannot use the same type of quote as text without escaping it. So the following won’t work:
echo 'what a 'lovely' dress, my dear';
But any of the following will:
echo "what a 'lovely' dress, my dear";
echo 'what a 'lovely' dress, my dear';
The opposite is also true – if you enclose with single-quotes, you can use double-quotes inside without escapes, but not single-quotes.
So look carefully at your multi-line string variable values, and make sure they are ending where you think they are. I haven’t used Smultron before, but in TextMate, the syntax coloring would have tipped you off quite alarmingly if you did this sort of construction.
You’re a master sleuth! Sherlock has nothing on you (and I mean Holmes, not Apple!)
I’ll take a look at that. The only thing that worries me is that Freeway is kicking out this code.
It also seems very odd to me that a lot of this code was already resident in the file and working without problems…see same pattern as you mention on lines 547/548, 573/574 etc. etc (wherever the product code links are).
Obviously it’s halting at the first instance of this and saying its an error. But the errors were there before and the file worked fine!
Had to hand amend the output file, but guess I’ll be able to work back through the places in Freeway where there are troublespots.
Just baffles me how it was working before…because it wasn’t just one instance of the single-quote issue…it was littered with them!
Just a note on Text Wrangler (Tim?)…how do you make the text bigger? I have to put my glasses on to look at a file! and can’t find where you make the default text bigger?
Hi Hugh,
Text Wrangler/Preferences/ Editor defaults/ and click on the Set…
button.
Regards,
Tim.
On 28 Jul 2010, at 12:22, hugh wrote:
Just a note on Text Wrangler (Tim?)…how do you make the text
bigger? I have to put my glasses on to look at a file! and can’t
find where you make the default text bigger?
I’m not sure how you are ending up with single-quotes in your Freeway-generated code. Are you using any Actions to validate forms, perhaps, or are you using the Freeway Shop stuff for Mals? Those might be quoting the values with single-quotes for some reason. Freeway by itself categorically does not use single-quotes inside the HTML it generates, and never has. The worst thing it does is drop the quotes entirely in some cases, which would not throw an error here.
No, none of that stuff, Walter…it’s all pretty kosher, no Freeway shop or Mals stuff, nor form validating actions.
What it DOES have (as I mentioned before) is some bespoke php code you wrote for me!! The stuff which allowed an active link to degrade to an inactive ‘finished’ state once a date had passed. (This works a treat, by the way!)
But even if it has something to do with your bespoke code (inserted via markup), why did it work before?..
I don’t really know. It’s not normal for the quotes to change like
that, and if I sent you the code, I probably would not have used
single-quotes to quote attributes. Finally, this is a totally blocking
error in any form of PHP there is, so it’s not possible for the code
to have been that way really and worked. Chalk it up to gremlins, or a
learning experience.
Walter
On Jul 28, 2010, at 10:42 AM, hugh wrote:
No, none of that stuff, Walter…it’s all pretty kosher, no Freeway
shop or Mals stuff, nor form validating actions.
What it DOES have (as I mentioned before) is some bespoke php code
you wrote for me!! The stuff which allowed an active link to degrade
to an inactive ‘finished’ state once a date had passed. (This works
a treat, by the way!)
But even if it has something to do with your bespoke code (inserted
via markup), why did it work before?..