|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-01-25 21:31 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
-Type: Feature/Change Request
+Type: Bug
[2020-01-25 21:31 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 13:00:01 2025 UTC |
Description: ------------ Usually problem happened with vendor libraries where authors try to write the code with private variables. Next day we want to rewrite the class with own constructor and own injected services. Ok, we can change visibility of all private properties. Then we can put into __construct own dependencies, set it to these properties. 1) We still need to call parent::__construct() otherwise we risk to lost half class functionality 2) We still need access to services that could be injected into library somewhere in /vendor/ folder. We usually "change" visibility level and expected to see these dependencies in our code. But nope. We should fill these props manually even if the properties was filled with dependency injector inside the library Test script: --------------- <?php class P { private $a; protected $b; public function __construct($a, $b) { $this->a = $a; $this->b = $b; } } class C extends P { protected $a; protected $b; private $c; public function __construct($c) { $this->c = $c; parent::__construct(1, 2); var_dump($this->a); // null, wtf, we pass 1 to parent! var_dump($this->b); } } var_dump(new C(1)); Expected result: ---------------- Changing visibility is actually CHANGING visibility. Not property behavior replacement.