0

I'm quite inexperienced with OOP.

I'm creating an MVC framework as an exercise. I would like to be able to autoload external classes into properties of the main controller (based on specific settings). To make this question more simple, how can I add properties/methods from outside a class?

I have this class:

class Controller {

    public $property = array();

    public function getProperty() {
        return $this->property;
    }

}

I would like to add a property (i.e: $second_property) from outside the class, without having to create an instance. Is it possible with PHP 8?

Luca Pennisi
  • 85
  • 10
  • Did you try it to see if it is possible? – miken32 Dec 12 '20 at 20:08
  • Is there a specific reason why you don't want to add both properties to the class? If the class needs two properties, then define two. – El_Vanja Dec 12 '20 at 20:09
  • Because these properties should be inserted dynamically. I'm trying to build an MVC framework as an exercise. One important feature is to be able to autoload classes based on a custom array and put them into a property of the main controller. Therefore, I don't know in advance which properties I will be going to add. – Luca Pennisi Dec 12 '20 at 20:13

0 Answers0