Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Cannot access parent:: when current class scope has no parent in

Tags:

php

public function __construct() {
    parent::__construct();
    $this->load->config("master");
    $this->oops();
    $this->database();
    $this->load->config("lang");
    $this->load->model("functions");
}

what is wrong with the code? i have no idea whats wrong! Can anyone help me pls?

Sorry for my english, i come from germany!

like image 234
slyceR Avatar asked Oct 28 '14 02:10

slyceR


1 Answers

parent:: is for accessing the parent classes implementation of a method. Your class doesn't have a parent, because it does not extend any class. Hence the error.

class Foo {

    public function bar() {
        echo 'bar';
    }

}

class Baz extends Foo {

    public function bar() {
        parent::bar();
        echo 'baz';
    }

}

Here parent makes sense, because there is a parent class.

class Foo {

    public function bar() {
        parent::bar();
    }

}

Here parent makes no sense, because there is no parent, hence error. Since it doesn't make sense and serves no purpose, just remove it.

like image 59
deceze Avatar answered Sep 20 '22 21:09

deceze