5
votes

I have everything correct and I have closed ?> the php tag and it still shows the error:

Parse error: syntax error, unexpected \'?>\', expecting function (T_FUNCTION)

This is my code:

<?php

class IWP_MMB_ErrorLog extends IWP_MMB_Core {

    function __construct() {
        parent::__construct();
    }


    function get_errorLog($args) {
        $myfile = fopen(ini_get('error_log'), "r") or die("Unable to open file!");
        // Output one line until end-of-file
        while (!feof($myfile)) {
            $string = fgets($myfile);
            $ar = explode("]", $string);
            if (!empty($ar[0])) {
                $remove = trim($ar[0], "[");
                $remove1 = trim($remove, "UTC");
            }
            if (!empty($ar[1]) && !empty($ar[0])) { 
                $error_data[] = array(
                    'date' => $remove1,
                    'content' => $ar[1],
                );
            }
        }
        fclose($myfile);
        return $error_data; 
    }
}

?>
1
Please post the exact error message you get!Rizier123
actually the closing ?> is redundant and MIGHT cause problems with any kind of header directives...ITroubs
The closing PHP tag (?>) is indeed, not needed, if there isn't anything else after it. It does not cause any kind of problems by itself; the presence of whitespace characters (spaces, new lines) after it causes the header problems. It's a good practice to not mix HTML and PHP in the same file and if you follow it then the next step is to get rid of the closing PHP tag in the PHP files.axiac
The error indicates that you have not closed a } somewhere. I cannot see where in what you posted, triple check your own local code.deceze

1 Answers

0
votes

I have a similar problem while using NetBeans. The file looks perfectly fine, but I get the same error as you. I suppose NetBeans needs some configuration, but what helps is just creating a new file, copy paste everything that's inside and rename the file... Dirty solution but works...