Error after hosting website

Asked

Viewed 96 times

0

I have a problem and I don’t know how to solve it. My college colleagues and I created a PHP in clear localhost, when we host it displays the following error:

Notice: Use of Undefined Constant DIR - assumed 'DIR' in /home/Storage/2/3e/Eb/noticiasdasgerais/public_html/yteste/Loader.php on line 19

Notice: Use of Undefined Constant DIR - assumed 'DIR' in /home/Storage/2/3e/Eb/noticiasdasgerais/public_html/yteste/Loader.php on line 19

Notice: Use of Undefined Constant DIR - assumed 'DIR' in /home/Storage/2/3e/Eb/noticiasdasgerais/public_html/yteste/Loader.php on line 19

Notice: Use of Undefined Constant DIR - assumed 'DIR' in /home/Storage/2/3e/Eb/noticiasdasgerais/public_html/yteste/Loader.php on line 19

Could someone give me a hand? We need to deliver this paper this week.

Here is the code snippet from line 19

function __autoload($className) {

    $r = new RouterController;

    //procura primeiro na raiz da app
    $classpath = array('Lib', 'helpers', 'Model', 'Controller');
    $classFile = $className . ".php";
    $loaded = false;
    $mod_path = __DIR__ . "/$path" . "/$classFile";

    if (is_readable("$mod_path")) {
        require "$mod_path";
        $loaded = true;
        break;
        //return false;
    }

    if (is_readable("$path$classFile")) {
        require "$path$classFile";
        $loaded = true;
        break;
        //return false;
    }

}       

$reserved = array('finfo');

if ($loaded == false && !in_array("$className", $reserved)) {
    $baseurl = $r->base();
    //@Router::redirect("$baseurl/404.php?return=$baseurl");
    exit;
}
  • 1

    You haven’t defined the constant DIR, see error message: Use of Undefined Constant DIR.

  • 1

    It wouldn’t be a mistake, like the Notice message itself, but you could use the dirname(FILE) instead of DIR

  • you have to change the localhost variables to the ones in the serverhost or check the dophp version to change dir to dirname(file) as the colleague mentioned for example

  • Now appeared these: Notice: Use of Undefined Constant FILE - assumed 'FILE' in /home/Storage/2/3e/Eb/newssgerals/public_html/yteste/Loader.php on line 19 Parse error: syntax error, Unexpected T_OBJECT_OPERATOR in /home/Storage/2/3e/Eb/newssgerais/public_html/yteste/Controller/index.php on line 7

  • What is that DIR does? Did you define it? What is the purpose of it and how is it used? Please [Edit] the question and add these details.

  • Edit your question with the code snippet for "/home/Storage/2/3e/Eb/noticiasdasgerais/public_html/yteste/Loader.php on line 19"

  • @Márvinedge I formatted your code there in the question, but realize she’s wrong. The function is finished and there is still code after which I imagine it should go inside the function. Confirm that this is how it is in your code.

  • your $baseurl is set to?

Show 3 more comments

1 answer

1


That constant __DIR__ exists only as of version 5.3.0 of PHP.

Maybe the error is because the localhost has this version, or higher, installed, but the final hosting does not have.

EDITED:

If you do not insist on updating the final version of the hosting, do as well as suggested by Otto and use dirname(__FILE__) instead of __DIR__.

  • The DIR error has been solved, only another line has appeared Parse error: syntax error, Unexpected T_OBJECT_OPERATOR in /home/Storage/2/3e/Eb/noticiasdasgerais/public_html/yteste/Controller/index.php on line 7

  • What is on line 7? You could publish the index.php code?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.