Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113286 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 27313 invoked from network); 26 Feb 2021 12:36:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Feb 2021 12:36:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6F5B21804E1 for ; Fri, 26 Feb 2021 04:25:45 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 26 Feb 2021 04:25:42 -0800 (PST) Received: by mail-io1-f50.google.com with SMTP id a7so9384975iok.12 for ; Fri, 26 Feb 2021 04:25:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hfgd1mGsGGRwLm3/tf3R4cnXPuKR7C+KS1jBZjmwsD0=; b=aZa1DpTcQNTzS5ujMjJlBabWj2eTiF8zkN4/O4UlHHyVY670jnAA+Yz75TUXPbEL40 0+5UVyM3YkBrGhJt6T6zlOe9wEFMIhZWYrMr7lR8hv63f1n73o7JDh9yJjE+TdFZZyjx mhNZsuK6nIniVyd8qRuGgBOZBtGVneVxwZj4UmqXf+ofbEqO9jZQzn6I9aRUkOuPXbZf 38UQw24VyY67HGq/Y5wXvKDpbyo/TKDYp9UGtHmTDoTdq9AJS1eItwk2Vphod7hwFBoJ fwgTeUqPPWFnqjpsOvlSdO9cClyRg3j3xxR+qbQSsn67U6q55BN5RImNj7ObiZPxgH4r /Bzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hfgd1mGsGGRwLm3/tf3R4cnXPuKR7C+KS1jBZjmwsD0=; b=Xo9pcvPOMd8ihhfjCS0c+xPTu4TEO86idOkQ5XYmUaDi7PnaMV06FS8WxsyDJjga+v 7BAJ3iahheYmKUlAMDs/mv2J2aIxc9TtQgB/T8x8fKoKgZ745rZMGtkl7TCPSNSRsQtK 55dAEk1yQtApkPO60Nf9JNFalB91rFdbbSIPxxw7MsXBam+sNIHjEp0J6+ljiXZ6q2kk 1NrRdZnU+Cmr6phzLBo41TdATEU6aS1iRzIKVN+Pe4UobH7ICzG5pxRY374n4C8SIuaB dRpExU/8kZLt1qLCs6SL6sQaxngb323lQGwxBpw5IQvRIny4JUpfgsxTR1vELZvkA1NM k9/A== X-Gm-Message-State: AOAM531W06gbEO+JoMJtjIe6+BTg6hFk+fV83XdPxCns0O7JpddfPRHY YiswTAJRHE44zKmH8ODBishB893BW8LEypTM4FQ= X-Google-Smtp-Source: ABdhPJwfFBedNie1VDBHoUREhySb1KlRLseIdMa/yHkLy3N13dIRHfBeiCBvbc75nmnRr2p9f8Yr3gGjpK+Stmum1U4= X-Received: by 2002:a6b:b304:: with SMTP id c4mr2564381iof.139.1614342341249; Fri, 26 Feb 2021 04:25:41 -0800 (PST) MIME-Version: 1.0 References: <177db7bbf72.ecf4615f732310.8822018854991483226@manuelcanga.dev> <177dd68f109.c748581d17565.7200783349436492456@manuelcanga.dev> In-Reply-To: <177dd68f109.c748581d17565.7200783349436492456@manuelcanga.dev> Date: Fri, 26 Feb 2021 13:25:30 +0100 Message-ID: To: Manuel Canga Cc: David Gebler , Internals Content-Type: multipart/alternative; boundary="000000000000cbcdb105bc3c5d8c" Subject: Re: [PHP-DEV] [RFC] class_name:namespace From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=) --000000000000cbcdb105bc3c5d8c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Manuel, pt., 26 lut 2021 o 09:17 Manuel Canga napisa=C5=82(a)= : > Hello, another example with "factories method"[1]: > > ```php > use MyProject\Framework; > > abstract class AbstractController { > private const HELPER_PATH =3D static::namespace.'/Helpers'; > private const SERVICE_PATH =3D static::namespace.'/Services'; > > public function instanceHelper( string $helperClass ) { > $helperClassName =3D self::HELPER_PATH."/{$helperClass}"; > > return new $helperClassName(); > } > > public function instanceService( string $serviceClass ) { > $serviceClassName =3D self::SERVICE_PATH."/{$serviceClass}"; > > return new $serviceClassName(); > } > } > > use MyProject\MyModule; > > class Controller { > public function __invoke() { > //...... > $date =3D $this->instanceHelper('Date'); > //... > } > > } > ``` > > [1]: https://en.wikipedia.org/wiki/Factory_method_pattern Personally, none of the above examples is convincing bc I'd implement them using a fixed class names map to avoid loading untrusted classes. Any kind of helper class is something I'd personally not use to avoid static coupling of code and hacks while writing unit tests over services that could be injected by IoC. Full class names (whether they're aliased or used in use clause) have more benefit over class name string operations as they're easy for any renaming which most of the IDE's these days can handle. IMO introducing namespace magic constant has relatively narrow use and I'd probably vote NO on this. Cheers, Micha=C5=82 Marcin Brzuchalski --000000000000cbcdb105bc3c5d8c--