DEV Community

Discussion on: Is it a bad practice ?

Collapse
anotherglitchinthematrix profile image
Alican YILDIZ • Edited on

I don't think so, it's a feature of the language. But I think it would be better to extend the class that you want to alter, this would be the cleanest and most flexible way to do that, since MyFoo extending the Foo class and sharing the same underlying structure.

<?php

class MyFoo extends Foo
{
    public $propertie_Not_Excplicitly_Defined;

    public function __construct(...$args)
    {
        $this->propertie_Not_Excplicitly_Defined = "World";
        parent::__construct(...$args)
    }
...
Enter fullscreen mode Exit fullscreen mode
Collapse
jeremymonatte profile image
Mbenga Author

yes I agree with the extend solution, but I am in a particular case where I cannot really use it
So i think about this walkaround, but I didn't really know if it's ok or really bad