Parse Error - unexpected T_STRING, expecting T_OLD...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Parse Error - unexpected T_STRING, expecting T_OLD...

Post by mcccy005 »

I've just transferred my code from my computer to a web server and trying to get around a few problems that are arising (ie. none of my code seems to work).
One of the errors I'm getting is as follows: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' .
And here's the code:

Code: Select all

session_start( );
require_once("input_page.php");
require_once("input_field.php");
 
class input_set
{
    protected   $previous_image,    //ERROR OCCURS HERE
        $next_image,
        $submit_image,
 
...
The web server version of PHP is 4.4.7 (which is funny because they told me they used version 5!!) and my version which was working on my computer was version 5.2.1.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Parse Error - unexpected T_STRING, expecting T_OLD...

Post by Chris Corbyn »

That code is PHP5-only. If you've written much code like this and want to run it in PHP4, be prepared to spend a lot of time hacking away to make it work ;)

PHP4 didn't have all the fancy OOP stuff like PHP5 does. You'll need to change that "protected" to "var" for a start. Any constructors need to be change from __construct() to the name of the class itself. Any interfaces or abstract classes need to be dropped. Any static class fields need to be removed. Any destructors won't work. But most annoyingly, PHP4 doesn't handle object references correctly so you need to use the "&" reference operator everywhere to explicitly create references to objects which don't behave the same as proper object handles in PHP5.

Fortunately for hosts who upgrade to PHP5, and for developers who wrote PHP4 code, PHP5 is backward compatible with PHP4 code, but not vice-versa.

I'd suggest find a new host or asking your host to upgrade since PHP4 is out of development as of December 2007.
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Re: Parse Error - unexpected T_STRING, expecting T_OLD...

Post by mcccy005 »

Thanks a lot for that advice.
My web host has just informed me that I can upgrade to version 5 which is good news based on what you've just mentioned to me - all of my code was learned using, tested using and developed using PHP 5!
Thanks for the information though - most helpful.
Post Reply