phpfunctionphp-parse-error

Parse error: unexpected '@' symbol in constant function in php


In my project, when I try to install a software, I got an parse error in last step of installation

The parse error is

Parse error: syntax error, unexpected '@' in /path/to/server/subfolder1/projectfoldername/subfolder/filename.php on line 21

The coding in that particular line of that file is

if(@constant($matches[1][0]) != @$matches[1][0]){
        if(!empty(@constant(@$matches[1][0])) & !empty(@$matches[0][0]) & !empty(@$design_m_r[$key])){
           $design_m_r[$key] = @str_replace($matches[0][0], constant($matches[1][0]), $design_m_r[$key]);
         }
        }

Our site php version is php 5.3.28. I tried to search for this error. But I dont get any solution for this. Some of the forums told about this error as "This is the advanced php version functions. So this should not support for php 5.3.28 version". But when I searched, there is no versions used this type of function.


Solution

  • You can't use the @ error suppression operator like that.

    From the PHP Docs..

    The @-operator works only on expressions. A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it. For instance, you can prepend it to variables, function and include calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such as if and foreach, and so forth.

    Also, passing arbitrary expressions on empty is allowed only from PHP 5.5 .