Question

Here are two versions of a line in a php file:

First version:

if ($projet['sourceDonnees'] === (string)$CONSTANTS['sourceDonnees_saisie']) {

Second version:

if ($projet['sourceDonnees'] === (string)$CONSTANTS['sourceDonnees_saisie']) {

Although they look identical, the first version results in a PHP Parse error: syntax error, unexpected T_STRING, whereas the second version works fine. The difference between the two is that the first version was pasted in and modified whereas the second version was written out by hand entirely. What's going on here?

Notes: The line was copied from a text file encoded in UTF-8 and pasted into another UTF-8 text file. All operations done within gedit, both files written by me in gedit.

Was it helpful?

Solution 2

When I copied & pasted your first line into my text editor and turned on the "show invisible characters" option, it looked like this:

enter image description here

if ($projet['sourceDonnees']•=== (string)$CONSTANTS['sourceDonnees_saisie']) {

Notice the between the ] and the ===.

Your second line of code showed perfectly clean.

Many times you will pick up stray invisible characters when you copy & paste text from websites. However, I do not know what keyboard combination will reproduce this from scratch.

Further experimentation reveals this invisible character as "non-ASCII"... the BBEdit text editor simply calls them "gremlins", and even has a "zap gremlins" function.

OTHER TIPS

You've copied UTF-8 quote marks, which are not parse-able by PHP. Remove the quote marks and replace them with ASCII equivalents (i.e. by typing them).

For more information on ASCII vs UTF-8 quote marks see http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html

unexpected T_STRING is usually an issue with your quotes or tick marks. The 's in the code that you copied are UTF-8 and probably a version of the quote that PHP cannot parse, like the backticks we use for inline code here on SO. Try changing them to a regular single quote and it'll likely solve your issue.

If that's not the case, make sure you didn't miss the semicolon at the end of your function. This can cause the same error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top