Is it a bad practice ?

Posted on

Is it a bad pratice to do that :

<?php
class Foo
{
    public $propertie_Excplicitly_Defined;

    public function __construct()
    {
        $this->propertie_Excplicitly_Defined = "Hello";

}

$bar = new Foo();
$bar->propertie_Not_Excplicitly_Defined = "World";

Enter fullscreen mode

Exit fullscreen mode

And if it’s, why?

I have to pass a new variable to an object whose structure I cannot modify, and I didn’t find a better way to do it. So is it bad or is it ok ? And if it’s bad, do you have an idea about how i should do ?

Thanks a lot

Leave a Reply

Your email address will not be published.