Jump to content
  • 0

Непонятная ошибка класса


vvsh
 Share

Question

require_once 'config.inc.php';

class Core {
function __construct() {
global $config;
$this->config = $config;
}

function Init() {

}

function Load_class($name) {
require $name.'.php';
return new $name;
}
}

$Core = new Core();
$Core->Init();

$User = $Core->Load_class('User');
echo $User->data();

Код класса User

class User extends Core {
function __construct() {

}

function data() {
return $this->config['db']['prefix']; // Строка 8
}
}

Выдает ошибку

Notice: Undefined property: User::$config in file on line 8

Но если убрать из User, __construct, то ошибка пропадает. в чем дело?

Edited by vvsh
Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0
Ошибка, очевидно, от того, что в классе User нет никакого поля $config.

А вот то, что после удаления __construct() она пропадает - это у вас что-то непонятное творится.

Вообще-то User наследует Core.

Edited by vvsh
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy