What's the meaning of "PHP Parse error: parse error, unexpected $ in..."
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Yes, yes, yes!!!
That was, actually, my first thought
But I checked through out the code to find the same as you: nothing.
The comment on the include was a comment I put when I was re-checking for problems on the include files. Nothing.
As you said you confirmed it worked on PHP4, It was working before.
Now I'm taking yours and greamef piece of advice: I'm putting the code back little by little to see where's the problem.
I'll keep you posted.
Quote:
Originally Posted by Spudley
When you get this error on the last line of your PHP, it usually means that you left something unclosed -- ie mismatched brackets, php tags, or something like that. PHP freaks out because it gets to the end of the program and is expecting more code; it's reporting "unexpected $" because it treats the blank line after the final ?> as a print statement (ie print a carriage return).
As you say, it works in PHP4, and I don't have php5 on my box to test it with. Looking at the code, I can't see anything obviously wrong, but the line <?//include("menu.php");?> makes me wonder if php5 is treating the comment differently, and including the ?> in the comment, in which case, it would definitely cause problems. So maybe try changing that to use /*...*/ comment style instead.
I honestly can't see anything else that would cause problems. Hope you manage to solve it... If all else fails, split it down into bits, and see which one breaks.
Old topic, I know - found it via Google since I had the same problem today. I had the same parse-error - without reason! - I was convinced the code was ok.
After trying some things I found the solution (for me at least). The problem is in the whitespaces. In my case for some reason my file was 'polluted' with windows-spaces (CF). I changed all these into unix spaces (LF) and I got rid of the weird parse-errors from PHP.
To convert spaces unix-style:
- open your file with notepad++ (notepad-plus.sourceforge.net) (other editors might also be able to do this)
- Go to > format > convert to unix format.
- save and smile (I hope)
That did the tric for me. Hope this reaction might still be usefull for someone.
Note for beginning PHP-programmers: first check all the points mentioned before! It might actually be a PHP parse error caused by a typo.
Hi, I just had a struggle with such an issue. I came up with a following solution. It will help to have Linux, or similar scripting environment and commands to use.
I have "index.php" which I run to make an index.html file. It was this file which I had my error. I decided to create the following script so that I could 'target' my bug.
So I ran this script. It essentially breaks up your code and parses the cut up versions of your code. Different lengths of the file are parsed according to the foreach line in the script. I received this output
Code:
---------------------50-------------------------
---------------------100-------------------------
---------------------150-------------------------
PHP Parse error: parse error, unexpected $ in /d/home/coltharp/public_html/ex/page.builder/Xindex.php on line 151
---------------------200-------------------------
PHP Parse error: parse error, unexpected $ in /d/home/coltharp/public_html/ex/page.builder/Xindex.php on line 201
---------------------250-------------------------
PHP Parse error: parse error, unexpected $ in /d/home/coltharp/public_html/ex/page.builder/Xindex.php on line 224
It just so happened that line 150 was inside a foreach block. So this result did not key me in to my bug. But I continued changing the foreach line in the csh script. Finally I found a place where I had accidentally commented out a closing bracket. Hope this helps!
I HAVE A PROBLEM WHAT SHOULD I DO, THE PROBLEM IS THIS WHEN I TRY TO OPEN A SITE THEN THIS COME ON SCREEN:Parse error: parse error, unexpected T_STRING in /hsphere/local/home/nohani/baask.com/diwan/Settings.php on line 28,WHAT IS THE SOLUTION??
Last edited by hamgerench; 03-06-2008 at 04:11 AM.
"Unexpected $ on line 59" means that there is an unexpected end of file. '$' is used to indicate end of file. It means that usually a closing '}' is forgotten or a ';'
This is one of the obscure error messages of PHP, no matter how powerful PHP is, the error messages are sometimes obscure. (But you get used to it)
I read this thread about php parser erros and I too have a .php parser error in the PaymentMethod.php file for my cart:
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 133: parser error : Opening and ending tag mismatch: usaepayach line 107 and payach in /home/the/domains/silverborn.com/public_html/lib/Varien/Simplexml/Config.php on line 500
I know that the parsing error exists in the paymentmethod.php file because before I modified the original Adapter Model code, I could access my configuration settings in admin>system>Configuration. Now I have no access to my store’s configuration at all.
I could post the complete .php code but since it’s a payment module, I think it would be best to have someone help me fix it by sending him/her the complete code via private message asap.
Please help me fix this so I can access my configuration settings. I know it's a simple fix but I'm new to php.
But things like this happend to me all the time.
Just looking at the source, i see a problem (not so obvious may be): I will quote :
<?php
session_start();
include("file.php");
$query="select * from user where user_name = '".$_POST['user']."';";
$link = mysql_query($query);
$line = mysql_fetch_array($link);
if((isset($_SESSION['pass']))||($line['user_pass'] == sha1($_POST['pass'])))
{ // ---------- HERE IS ONE OPEN
if(!isset($_SESSION['pass']))
{ // --------- HERE IS SECOND OPEN
$_SESSION['user'] = $_POST['user'];
$_SESSION['pass'] = $_POST['pass'];
} // ---------HERE CLOSES ONE
?> // HERE THE SCRIPTS END, WITH UNBALANCED PARENTHESIS
the rest is ignored.. the script is searching for a command
<html>
<head>
..
..
..
Sometimes indenting the source helps a lot
three years late, but the true is revealed
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.