Fatal error: Uncaught Error: Call to a member function get () on null

0

I have been with this problem for a little more than a day, I checked the possible similarity of my question with others, but the truth, none of them worked for me.

I'm having the following error in PHP: Fatal error: Uncaught Error: Call to a member function get() on null

File Url.php , line 28.

Url.php :

<?php

class Url extends App {

 private $db;
 private static $alias = null;
 private static $mcpe_list = null;
 private static $url2 = null;
 private static $clicks = 0;
 private static $name = null;
 private static $password = null;

 public function __construct() {
  $this->db = json_decode(file_get_contents('/../' . $this->config->get('DB_PATH')), true);
 }

}

App.php :

<?php

class App {

 protected $error;
 protected $url;
 protected $config;

 const CFG_PATH = 'private/config.json';
 const VAL_ERRORS = [400, 401, 403, 404, 500];

 public function __construct() {
  $this->error = new Error();
  $this->url = new Url();
  $this->config = new Config(self::CFG_PATH);
 }

}

The error, $this->config->get('DB_PATH') occurs in the constructor of class Url.

Instances are created in the App class and as Url extends App, the protected properties are inherited.

Thanks for your answers.

    
asked by Derek Nichols 05.08.2017 в 17:00
source

1 answer

1

I hope I can help you despite my little experience.

The error says that you are trying to access a method on null, the object $config is clearly not instantiated.

I have researched a bit and the solution is to explicitly call the parent constructor inside Url :: __ construct (), you can do it this way:

 parent::__construct() 

I hope my contribution will be helpful.

Good luck!

    
answered by 05.08.2017 в 18:18