Strange PHP syntax error O.o

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
User avatar
lorenzo-s
Forum Commoner
Posts: 43
Joined: Tue Aug 25, 2009 12:25 pm

Strange PHP syntax error O.o

Post by lorenzo-s »

Same PHP file on two different servers. One is ok, the other says:

Code: Select all

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /web/htdocs/www.fototue.it/home/_test/test.php on line 18
Line 18 of my script is a static function in a class:

Code: Select all

public static function my_function(&$arg = null) {
First server (ok): PHP 5.2.8 on Windows NT.
Second server (error): PHP 5.2.10 on Linux.
Differences in configuration are on INI directives that I know.

HEEELP!! :banghead: :banghead:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Strange PHP syntax error O.o

Post by requinix »

What's all the code within 15 lines of that?
User avatar
lorenzo-s
Forum Commoner
Posts: 43
Joined: Tue Aug 25, 2009 12:25 pm

Re: Strange PHP syntax error O.o

Post by lorenzo-s »

All the file:

Code: Select all

 
    class Utils {
        
        /** Perform stripslashes() and trim() on Request data, array or string. */
        public static function striptease(&$arg = null) {
            
            // GET on POST, if magic_quotes are ON
            if (is_null($arg)) {
                if (!get_magic_quotes_gpc()) return;
                foreach ($_GET  as $k => $v) $_GET[$k]  = trim(stripslashes($v));
                foreach ($_POST as $k => $v) $_POST[$k] = trim(stripslashes($v));
            
            // Array
            } elseif (is_array($arg)) {
                foreach ($arg as $k => $v) if (is_string($v)) $arg[$k] = trim(stripslashes($v));
            
            // Simple string
            } else {
                $arg = trim(stripslashes($arg));
            }
            
        }
 
    }
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Strange PHP syntax error O.o

Post by superdezign »

Are you positive that the files on both servers are exactly alike?
Also, try breaking up your function declaration into different lines. Whitespace means nothing in PHP, so this will help you determine which keyword PHP is spitting back at you.
User avatar
lorenzo-s
Forum Commoner
Posts: 43
Joined: Tue Aug 25, 2009 12:25 pm

Re: Strange PHP syntax error O.o

Post by lorenzo-s »

superdezign wrote:Are you positive that the files on both servers are exactly alike?
Exactly. Uploaded just now via FTP with binary mode transfer.

Maybe I can't define a default value for a reference passed variable? I mean, maybe I cannot do:

Code: Select all

my_f( &arg = null ) {}
I will try split it...
User avatar
lorenzo-s
Forum Commoner
Posts: 43
Joined: Tue Aug 25, 2009 12:25 pm

Re: Strange PHP syntax error O.o

Post by lorenzo-s »

lorenzo-s wrote:I will try split it...
I wrote:

Code: Select all

class Utils {
    public 
    static 
    function 
    my_function
    (
        &$arg = null
    ) 
    {
    }
It throw the same initial error on line public. Error says unexpected T_STRING like PHP thinks that public is a string. Indeed then says: expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'...
User avatar
lorenzo-s
Forum Commoner
Posts: 43
Joined: Tue Aug 25, 2009 12:25 pm

Re: Strange PHP syntax error O.o

Post by lorenzo-s »

Deleting the keywords public AND static, the script works! 8O 8O 8O

Maybe I found the problem. On the server machine PHP 5.2.10 is installed, I am SURE, but in the hosting panel I found an entry where it's written that PHP 4.4.9 "compatibility" is used. Sorry guys for the time lost, but this was quite unbelievable for me, never seen before...
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Strange PHP syntax error O.o

Post by requinix »

You probably have to name the file with a .php5 extension.
Post Reply