Req #79169 [NEW]: When we replace property visibility in child class we still get [null]
| From: | 6562680 at gmail dot com | Date: | Sat, 25 Jan 2020 20:10:08 +0000 |
| Subject: | Req #79169 [NEW]: When we replace property visibility in child class we still get [null] | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-225111@lists.php.net to get a copy of this message | ||
From: 6562680 at gmail dot com
Operating system: Win10
PHP version: 7.3.14
Package: *General Issues
Bug Type: Feature/Change Request
Bug description:When we replace property visibility in child class we still get [null]
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.
--
Edit bug report at https://bugs.php.net/bug.php?id=79169&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79169&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79169&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79169&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79169&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79169&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79169&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79169&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79169&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79169&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79169&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79169&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79169&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79169&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79169&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79169&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79169&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79169&r=mysqlcfg