Hola Manuel,

"Don't you think the same ?"

I was thinking of something more generi, maybe :

```

namespace Foo\Bar;

class A {
    static function getNamespace() {
        static $ns = __NAMESPACE__;//
https://wiki.php.net/rfc/static_variable_inheritance
        return $ns;
    }
}

namespace My\Baz;
class B extends \Foo\Bar\A { }

echo \Foo\Bar\A::getNamespace(), PHP_EOL;// Foo\Bar
echo \My\Baz\B::getNamespace(), PHP_EOL;// Foo\Bar  Ho no !

```
Unfortunately it doesn't work ...

Best regards,
Serge

Le ven. 26 févr. 2021 à 09:26, Manuel Canga <p...@manuelcanga.dev> a écrit :

> I'm Sorry, I feel a little nervous by writing here again after long time.
>
> Replace '/' by '\' and PATH( HELPER_PATH | SERVICE_PATH )  by NAMESPACE(
> HELPER_NAMESPACE | SERVICE_NAMESPACE  ).
>
>
> Sorry
>
>
>
>
>
>
>  ---- En vie, 26 feb 2021 09:16:18 +0100 Manuel Canga <p...@manuelcanga.dev>
> escribió ----
>  > Hello, another example with "factories method"[1]:
>  >
>  > ```php
>  > use MyProject\Framework;
>  >
>  > abstract class AbstractController {
>  >     private const HELPER_PATH = static::namespace.'/Helpers';
>  >     private const SERVICE_PATH = static::namespace.'/Services';
>  >
>  >      public function instanceHelper( string $helperClass ) {
>  >             $helperClassName = self::HELPER_PATH."/{$helperClass}";
>  >
>  >            return new $helperClassName();
>  >     }
>  >
>  >    public function instanceService( string $serviceClass )  {
>  >             $serviceClassName = self::SERVICE_PATH."/{$serviceClass}";
>  >
>  >            return new $serviceClassName();
>  >    }
>  > }
>  >
>  > use MyProject\MyModule;
>  >
>  > class Controller {
>  >     public function __invoke() {
>  >                  //......
>  >        $date = $this->instanceHelper('Date');
>  >               //...
>  >     }
>  >
>  > }
>  > ```
>  >
>  > [1]: https://en.wikipedia.org/wiki/Factory_method_pattern
>  >
>  > Regards
>  > --
>  > Manuel Canga
>  >
>  > Zend Certified PHP Engineer
>  > Websites: https://manuelcanga.dev | https://trasweb.net
>  > Linkedin: https://es.linkedin.com/in/manuelcanga
>  >
>  > --
>  > PHP Internals - PHP Runtime Development Mailing List
>  > To unsubscribe, visit: https://www.php.net/unsub.php
>  >
>  >
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>

Reply via email to