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.
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Line 59 has a $ where there shouldn't be one. In other words, it doesn't start a variable name. Common causes may be lack of semicolon to end previous line, or invalid variable name, or unescaped end-of-input anchor for a regular expression. If you can't locate it, go ahead and post that area of your code and I'll be happy to take a look at it.
The point is: line 59 is the LAST line of the PHP code. Nothing last. It ends with a "}" on line 58 and 59 is a blank line.
I gotta leave very fast now. As soon as I get back I can post the whole code for you guys! thanks for the answers.
My guess: I think that $ means "end of line" (as in VI) and not a stray "$".
try to be back ASAP
I'm posting the code here for you.
I'm using php 5.0.5
I'm pretty sure there's no "$" hanging lost inside my code, I'm not such a beginner programmer.
Why am I guessing that?
This code used to work in my old linux installation. Now all files present me this very same error. I really don't know what to do.
My old installation was a 5.* PHP system.
I'll just try to rewrite the whole file and see what I can get. I have more than 10 files returning me the same error. Which was not here before. I wonder...
Any help will still be appreciated. Thanks to all who answered me. As soon as I have news I'll keep you up to date.
Originally Posted by paulsm4
I'd add to the list:
My guess is that you're having problems with the older dialect of PHP on your new PHP 5.0 system.
Again: please modify the syntax and try the "divide and conqueror" approach (steps 2 and 2).
Double check that it is this file that is being read by php and not another file with the same name in a different directory (that sort of thing)
change <? to <?php
Add a liberal dose of echo statements so you know where you are
As an aside your code would appear to be open to a SQL injection attack
Guys, this error don't get me even to start running the file! It just gives the error. It's most likely what Paulsm4 said. Something that my old install of php recognized as OK and can't do it now. strange indeed is, as the system was a 10.2 slackware system too. As I told you, I'll try rewriting the whole file. I'll keep you informed.
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.
It could be a problem in your included file (from the include() directive near the top) that's flowing over into this file. For example, a mis-matched parenthesis or bracket that's causing the parser to fail at the end of the whole input.
frandalla - please do what graemef is suggesting. He's given a very good example of what I was calling "divide and conquer"; he's making the excellent point that maybe the failure isn't even occurring on the file you think it is. Graemef's advice also ties in well with taylor_venable's and spudley's equally well-considered suggestions.