-1

子クラス (フィード) がメイン クラス (コントローラー) から変数を継承するようにしようとしています。

私は3つのファイルを持っています。それらは次のように見えます。

コアファイル:

/*  ----------------------------- *
 *  LOAD THE CONTROLLER CLASS NOW *
 *  ----------------------------- */
 require(CORE_PATH . 'controller.php');

 require(CORE_PATH . 'load_controller.php');

コントローラ クラス:

<?php

class Controller {

    var $sessions, $a;

    public function __construct() {
        $this->sessions = new Sessions();
        $this->a = 'yo';
    }
}

フィード クラス:

class Feeds extends Controller {
    public function feeds() {
        /* We can load other resources here */

    }

    function index($val) {
        echo $this->a;
    }
}

修正:

<?php require(PROTECT);

class Controller {

    protected $variable = "Setting the variable right here works.";

    public function __construct() {
        $this->variable = "Setting it right here will only work for the current object. It's as if variable isn't being set at all when it comes to other classes.";
    }
}
4

1 に答える 1