NotionCommotion Posted July 22, 2018 Share Posted July 22, 2018 If calling a parents constructor, it is considered better practice to duplicate the type declarations or just use them in the parent? Originally, I was doing for both, but it gets a bit cumbersome sometimes, and thinking of changing. Thanks namespace Base\Bla\BlaBla\Foo; class FooClass { protected $mapper, $validator, $pdo, $properties; public function __construct( Mapper\MapperClass $mapper, Validator\ValidatorClass $validator, \PDO $pdo, array $properties ) { $this->mapper=$mapper; $this->validator=$validator; $this->pdo=$pdo; $this->properties=$properties; } } Option 1 namespace Base\SpecificFoo; class SpecificFooClassx extends \Base\Bla\BlaBla\Foo\FooClass { protected $bar; public function __construct( Bar\BarClass $bar, $mapper, $validator, $pdo, $properties ) { $this->bar=$bar; parent::__construct($mapper, $validator, $pdo, $properties); } } Option 2 namespace Base\SpecificFoo; class SpecificFooClass extends \Base\Bla\BlaBla\Foo\FooClass { public function __construct( Bar\BarClass $bar, \Base\Bla\BlaBla\Foo\FooClass\Mapper\MapperClass $mapper, \Base\Bla\BlaBla\Foo\FooClass\Validator\ValidatorClass $validator, \PDO $pdo, array $properties ) { $this->bar=$bar; parent::__construct($mapper, $validator, $pdo, $properties); } } Quote Link to comment Share on other sites More sharing options...
requinix Posted July 22, 2018 Share Posted July 22, 2018 Duplicate them. Leaving them off is such an incorrect decision to me that I don't even have a clever way to answer your question. The types mean something. They aren't arbitrary. Writing those huge long class names is ridiculous, of course, but that's why PHP has the "use" keyword. use Base\Bla\BlaBla\Foo as Foo; class SpecificFooClass extends Foo\FooClass { Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.