Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113285 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22288 invoked from network); 26 Feb 2021 11:47:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Feb 2021 11:47:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1BAA81804F2 for ; Fri, 26 Feb 2021 03:36:46 -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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from sender4-op-o11.zoho.com (sender4-op-o11.zoho.com [136.143.188.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 26 Feb 2021 03:36:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614339402; cv=none; d=zohomail.com; s=zohoarc; b=RrE/FGKgA6U83cZ7HiyQHmG278jH9sy1U/4miKnboiNgQXa0mRirPZTXFGpX0oyXWcg6o7yMXgvDK45Wb02ZTKqSa0xgL3J2d4aZkxLwv6dC4lh8RlgRs+dpFav7eXCZnpVPyD1am7Ej5QamY/OxsE72zKZaoG1llq78akU7bho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614339402; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ZgvS+FSeKnYxbU0oSvnDXukWpKF2bi6y1aEX29AQLe8=; b=LlpYYFNcIMWbAASgbVYaFCVxKNxD+kFc3TFLy5cUuYVl+kQG7BIHuAXN449dvpbV0rYYljSxVGEOOukYIL8tKX6AwF0LNOWQbefUcyaAkDx7YE7rW4zTOLmRthNaHWmQHBv1hmuUODW1bKhTIKGzd3Ae2pgHaY1Ht7IMseQ03uQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=manuelcanga.dev; spf=pass smtp.mailfrom=php@manuelcanga.dev; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1614339402; s=zoho; d=manuelcanga.dev; i=php@manuelcanga.dev; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=ZgvS+FSeKnYxbU0oSvnDXukWpKF2bi6y1aEX29AQLe8=; b=P30I9U66JoNWlt5k8AySk90r4kad0/+sckUIdcJ0QDV9zrAsTivZEIRl9yO10DJt lb/+Gyx2TVZl2kgDiZ0YeWeTtJFzM8agf2S2K15fapw3xfHQwoR5a1Z8w0wL2ukPiV+ nUeELg6H2yjoPdm6FmzlCcP+lMiUxbBS+y+7VFT8= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1614339371446848.4397789361922; Fri, 26 Feb 2021 03:36:11 -0800 (PST) Date: Fri, 26 Feb 2021 12:36:11 +0100 To: "Claude Pache" Cc: "David Gebler" , "Internals" Message-ID: <177de1ff1a0.feee271246706.3311842089729077831@manuelcanga.dev> In-Reply-To: References: <177db7bbf72.ecf4615f732310.8822018854991483226@manuelcanga.dev> <177dd68f109.c748581d17565.7200783349436492456@manuelcanga.dev> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Subject: Re: [PHP-DEV] [RFC] class_name:namespace From: php@manuelcanga.dev (Manuel Canga) >=20 > Hi, >=20 > Note that (typos aside) this example cannot work as-is, because `static:= :namespace` (like `static::class`) cannot be resolved at compile-time, and = therefore cannot be assigned to a constant. >=20 > More generally, in the various examples you provided, the namespace is n= ot resolved at compile-time: it is either static::namespace or $fullClassNa= me::namespace where $fullClassName is provided by the autoloader. As such, = instead of a ::namespace magic class constant, it might be more appropriate= to have a helper function, say `get_namespace()`, which has the additional= benefit to work not only on (fully qualified) class names, but also on fun= ction, constant and namespace names (in the case of namespace names, it wou= ld return the name of the parent namespace). >=20 > =E2=80=94Claude >=20 > Hi, Claude, That's sound great. Something like dirname[1] but with namespaces. But...in that case, I also add a new function like basename but with namesp= aces. Example autoload for WordPress : ``` function autoload( $ful_class_name ) { $class_ path =3D str_replace('\\', '/', get_namespace( $ful_class_name ) ); $class_name =3D strtolower( get_base_namespace( $ful_class_name ) ); require "{$class_path}/class-{$class_name}.php"; }``` [1]: https://www.php.net/manual/es/function.dirname.php [2]: https://www.php.net/manual/es/function.basename.php Regards -- Manuel Canga Zend Certified PHP Engineer=20 Websites: https://manuelcanga.dev | https://trasweb.net Linkedin: https://es.linkedin.com/in/manuelcanga