子类不从父类继承属性

This isn't working the way I thought it would. Here are my classes:

class App {
    public $db;

    public function __construct($db) {
        $this->db = $db;
    }
}

class Analysis extends App {

    public $analysis_id;

    public function __construct($analysis_id) {
        $this->analysis_id = $analysis_id;
    }
}

class Standard extends Analysis {

    public function __construct($analysis_id) {
        parent::__construct($analysis_id);
    }
}

$db is my database (mysqli) object that I've passed to the App class.

When I try to perform a new Standard Analysis, I initiate it like this:

$analysis = new Standard($analysis_id);

The Analysis class contains methods that retrieve meta data about an analysis, while the Standard class contains methods that retrieve calculations for that specific type of analysis. I thought I would be able to access the $db object, but I can't from the Analysis or Standard class. Do I need to pass the $db object to the Standard class when I initiate it?

Your Analysis class needs to call the constructor on its parent, App. This doesn't happen by default. Because $db is a parameter of the App constructor, you will have to pass this in from the subclasses as well, and then call parent::__construct($db) from the Analysis constructor.

Correct code:

class App {
    public $db;

    public function __construct($db) {
        $this->db = $db;
    }
}

class Analysis extends App {
    public $analysis_id;

    public function __construct($analysis_id, $db) {
        $this->analysis_id = $analysis_id;
        parent::__construct($db);
    }
}

class Standard extends Analysis {
    public function __construct($analysis_id, $db) {
        parent::__construct($analysis_id, $db);
    }
}

$analysis = new Standard($analysis_id, $db);

Each object is independent of each other object. Just because you instantiated an App object somewhere does not mean that anything else has access to the data in that object, whether the classes are related or not. The $db argument you pass into an instance of App is available in that object and only in that object.

Inheritance inherits the object structure, not data.

$app1 = new App($db);
$app2 = new App($db2); // <- different app instance, different data
$app3 = new App;       // <- does not have access to $db
$std  = new Standard;  // <- also does not have access to anything in $app1