Req #79720 [NEW]: Nested classes like in Java

From: Date: Sun, 21 Jun 2020 16:34:26 +0000
Subject: Req #79720 [NEW]: Nested classes like in Java
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227570@lists.php.net to get a copy of this message
From:             6562680 at gmail dot com
Operating system: Win10
PHP version:      7.3.19
Package:          *General Issues
Bug Type:         Feature/Change Request
Bug description:Nested classes like in Java

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 bug report at https://bugs.php.net/bug.php?id=79720&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79720&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79720&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79720&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79720&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79720&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79720&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79720&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79720&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79720&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79720&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79720&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79720&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79720&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79720&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79720&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79720&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79720&r=mysqlcfg


Thread (3 messages)

« previous php.bugs (#227570) next »