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!
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:
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.
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));
}
}
}
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.
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 '}'...
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...