| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2021-11-11 03:00 UTC] requinix@php.net
 
-Status: Open
+Status: Not a bug
  [2021-11-11 03:00 UTC] requinix@php.net
  | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 15:00:01 2025 UTC | 
Description: ------------ $dog->database->insert(); ////WHY THIS WORKS? "database" beeing a protected variable in Model class Test script: --------------- <?php final class Database { public $connection = "database connection stream"; public function insert () { echo "inserted\n"; } } abstract class Model { protected $database = null; public function __construct () { $this->database = new Database(); } } class Dog extends Model { public function __construct () { parent::__construct(); } } class Cat extends Model { public function testProtected() { $dog = new Dog(); $dog->database->insert(); ////WHY THIS WORKS? "database" beeing a protected variable in Model class } } $cat = new Cat(); $cat->testProtected(); ?> Expected result: ---------------- I expect that $dog->database->insert(); gives me "Cannot access protected property Dog::$database Actual result: -------------- it works for some reason.