Page 1 of 1
Strange PHP syntax error O.o
Posted: Mon Sep 21, 2009 2:01 pm
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!!

Re: Strange PHP syntax error O.o
Posted: Mon Sep 21, 2009 2:09 pm
by requinix
What's all the code within 15 lines of that?
Re: Strange PHP syntax error O.o
Posted: Mon Sep 21, 2009 2:10 pm
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));
}
}
}
Re: Strange PHP syntax error O.o
Posted: Mon Sep 21, 2009 2:14 pm
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.
Re: Strange PHP syntax error O.o
Posted: Mon Sep 21, 2009 2:18 pm
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:
I will try split it...
Re: Strange PHP syntax error O.o
Posted: Mon Sep 21, 2009 2:26 pm
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 '}'...
Re: Strange PHP syntax error O.o
Posted: Mon Sep 21, 2009 2:44 pm
by lorenzo-s
Deleting the keywords
public AND
static, the script works!
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...
Re: Strange PHP syntax error O.o
Posted: Mon Sep 21, 2009 3:24 pm
by requinix
You probably have to name the file with a .php5 extension.