PHP Parse error: syntax error, unexpected T

I get this error in my PHP code:

PHP Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:Inetpubwwwrootwebrootwww.novotempo.org.brlibTwitter.php on line 54

The line in question:

define('DEBUG',false);

Searching the net I found that this usually occurs when you´re using PHP 4.xx, but I´m using 5.2.6 (Just checked it using phpinfo() ).

I tried locally, and in two other external hosts, but it keeps returning the same message.

Why does this happen? How can I fix it?


If you are trying to DEFINE something inside of a class but outside of a function, you are going to get this error.

(Normally the only place PHP will be looking for a function and not expecting a string is in a class, outside of a method)

IE: Your code should not look like this:

class myClass
{
    define("DEBUG", true);
    function myFunc()
     {
     }
}

Thanks for this, resolved an annoying issue quite quickly for me.

I'd also like to add that the use of hyphens in constant names doesn't work and is apparently expected behaviour. It seems as though the echo tries to evaluate mathematics (minus) on the words.

<?php
define('THIS-IS-A-TEST','Testing');
echo THIS-IS-A-TEST;
?>

Returns '0'

<?php
define('THIS_IS_A_TEST','Testing');
echo THIS_IS_A_TEST;
?>

Returns 'Testing'

链接地址: http://www.djcxy.com/p/69416.html

上一篇: 在PHP中,为什么</ script>不显示分析错误?

下一篇: PHP解析错误:语法错误,意外的T