Req #79720 [Opn->Sus]: Nested classes like in Java
| From: | requinix@php.net | Date: | Sun, 21 Jun 2020 20:00:23 +0000 |
| Subject: | Req #79720 [Opn->Sus]: Nested classes like in Java | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227593@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79720&edit=1
ID: 79720
Updated by: requinix@php.net
Reported by: 6562680 at gmail dot com
Summary: Nested classes like in Java
-Status: Open
+Status: Suspended
Type: Feature/Change Request
-Package: *General Issues
+Package: Class/Object related
Operating System: Win10
PHP Version: 7.3.19
Block user comment: N
Private report: N
New Comment:
*I* think there are already well-established OOP principles that make child classes irrelevant.
But regardless of what I think, a significant change like this requires the RFC process.
https://wiki.php.net/rfc/howto
But note that you're not the first to propose this:
A few years ago there was an RFC about nested classes. It was not completed.
https://wiki.php.net/rfc/nested_classes
The related concept of friend classes was submitted a bit more recently and declined.
https://wiki.php.net/rfc/friend-classes
Previous Comments:
------------------------------------------------------------------------
[2020-06-21 16:34:26] 6562680 at gmail dot com
Description:
------------
Am using \Closure with bind() to pass protected variables into instances from factory.
As i remember in Java we can define sharing this context to child classes.
Why it was removed?
```
Class A
{
public function newChildA()
{
$a = new ChildA;
$a->value = 123;
}
Class ChildA
{
protected $value;
}
}
```
Otherwise we should add setters, and somebody of course use it directly in his code.
Its about "readonly" property, not just "protected".
Main problem is "no internal dependency injector", we can pass attributes via
__construct... What if dependencies? We still need to create builder that should pass parameters to
constructor with autowired dependencies, and then we lost possibility to create object via
"new" operator, otherwise we should add container/di into each class as dependency.
Then we should remember base class dependency when extending and that stuff.
How do you think?
Test script:
---------------
Class A
{
public function newChildA($value)
{
$func = function ($value) {
$this->value = $value;
};
$a = new ChildA;
$func->call($a, 123);
}
}
Class ChildA
{
protected $value;
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79720&edit=1