Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124401 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id D81A21A00B7 for ; Fri, 12 Jul 2024 03:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1720754133; bh=LhMCtExmpEGo9+ukLS2wA+lplBt4vhuoEe+ef9i1Hug=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ezhxpZBZjRwh6RuzaFsRA/iQ8rvhkiYOMxS9VR9eYY0AGS8g1hBGuBzwoIl+6DB6f zjsnsT28F95Y+NgSQ/DPOG/dJM04M4IB+yx1ZwmRhIbpQBOJIVOjtQPB7vOldalizX /bRz22J0qVxuhnJPz6P6a4FFKq3eITLFM7PHbKqNxUX7XYsGaVYaB4fhp1uQu+f6RR qzl8Ycajb34qgCBDC8ho2weSDHHjOsMPqzNZCmSP6DRAjEfVEw+tfrLKzfP7niniBw dWXbe891y6d0eiWmCNxHfKfqmr6vaVnYaGfErE02b8l8pEt3AUH7iFIWYR2fdN4XJE SBQzWfYxGURrg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A489B18006E for ; Fri, 12 Jul 2024 03:15:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 12 Jul 2024 03:15:32 +0000 (UTC) Received: by mail-vs1-f47.google.com with SMTP id ada2fe7eead31-48ff19d7074so741799137.1 for ; Thu, 11 Jul 2024 20:14:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720754044; x=1721358844; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=e8JzmFpH+Q3RXxFOFVWQKg5zQVAoqdXm7O4pt9l/H/A=; b=EYkSodIqC8AA3o0CC077eankSjU7OJZXzQ3Bjt4bfbHkn0JW2XnbcF9Ss7xYkGvSKN GGn6aABkc44sL/Gicyxp35Q6Z9lUPi+Y1iBVa8EmQcoFMmGHYF58DgXfM8ZA/2197NbN iyPD8zNCbFcYY2MS0t9OObDtEm6XYonkhIjiyiqCZ4PZ5Y2cUYsPE9Y/eJ5Dm343aAtq 76j8D4ajk2KjwDhtRqCGi+LBFV5tHxEg5t6bO+rWra7oBm1Voso5NREYoExIEgh5osmW GbUaBvfiXlcQV5kVsTBixrqsB22RVHHMHn7aQejywKltc3LYk3clbmeAZOPcDH4Kk9wH bz+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720754044; x=1721358844; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=e8JzmFpH+Q3RXxFOFVWQKg5zQVAoqdXm7O4pt9l/H/A=; b=DwiPiscAgD76lptx3WkY4kdIiotA3NVAmAsGimk2El4uBRXTkMRnglGMsQso5nx4lc hD8pi8IMqqdUW0F1T/F+p1wexY/b7FXYtWKIYUy/5h46qWY5vJAwRaA1IBrIKIO3kY8l YkpQyc8bIpKxFRdDvlAAQmFrBVyG1+QELo/K7oF0ejr00PBYpWfFX+ejXit5VsMJPSvE 01N8FCET/SHizp6NjhEyz8HXjklAzD2CtXNZNwOW2CYDpolfvIjlNyAk7Xjf/83M+jiu aJerNjjfvpPWslzjCVn7jTMOJ1u0NXvzQjDZ9ioSmno65nu3f51yTPRmS7z7mq4KWQln NYFA== X-Gm-Message-State: AOJu0YxEpIYJ8smezx8EFA7mlqpMzTyral8/BPk+baXBqBCpgOHy6Ug5 PIDwjRpabg7Oeolo9W2+/oJaOjVlSWWVagkUnq5EzWdYHH7YM5nL8EXB6iuL5LIMLwWR4gXndoz vp3A6XRfMvkx9d1ohWLWpapnbAarsDctu X-Google-Smtp-Source: AGHT+IEBlb9jal8yuWMsX0M691EiehcNI4TCPSZ/SxZdmHzM6qtEIId2xFnbSPxnRN5T4fesi6CAGoSXxNvrs+dVS4M= X-Received: by 2002:a05:6102:5707:b0:48f:b5c1:7269 with SMTP id ada2fe7eead31-49119896c5fmr1183838137.0.1720754044449; Thu, 11 Jul 2024 20:14:04 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <4596aa73-cfd4-2292-7191-2839a5bab695@php.net> <132b86de-f571-4611-8b9b-35ae107901f0@scriptfusion.com> In-Reply-To: <132b86de-f571-4611-8b9b-35ae107901f0@scriptfusion.com> Date: Thu, 11 Jul 2024 21:13:53 -0600 Message-ID: Subject: Re: [PHP-DEV] [RFC] Static class To: Bilge Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000090bb3b061d04459d" From: lnearwaju@gmail.com (Lanre) --00000000000090bb3b061d04459d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jul 11, 2024 at 6:16=E2=80=AFPM Bilge wrot= e: > On 25/06/2024 16:17, Derick Rethans wrote: > > we shouldn't be encouraging static classes as a bag of static functions, = that ought to be just namespaced functions. > > cheers, > Derick > > Can someone clue me in as to why grouping related functions in a file wit= h > nothing but a namespace is strictly better than those same related > functions grouped as members of a class? It doesn't have to be Larry or > Derick, because even though they have expressed this view, I am aware the= y > are not the only ones whom hold it. Anyone who can shed some light on thi= s > perspective is welcome to comment. > > Cheers, > Bilge > It isn't implicitly better, but if PHP had proper support for autoloading functions, I would at least consider them equivalent when all the functions/methods are public. My primary language is C++, where the distinction is even blurrier since both static class members and namespace members are accessed with '::'. For example, X::Y() could be a namespaced function or a static method, and it doesn't actually matter which it is under the hood since they are functionally identical. In PHP, however, putting all your functions in a namespace is less performant than using static classes. For instance, if you have ten functions.php files each for a separate namespace, Composer will load all ten for every single request, regardless of whether they are used. Additionally, if you install a Composer package that registers some functions, those will also be loaded for every request. Cheers, Lanre --00000000000090bb3b061d04459d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Thu, Jul 11, 2024 at 6:16=E2=80=AFPM B= ilge <bilge@scriptfusion.com> wrote:
=20 =20 =20
On 25/06/2024 16:17, Derick Rethans wrote:
we shouldn't be encoura=
ging static classes as a bag of static functions, that ought to be j=
ust namespaced functions.

cheers,
Derick

Can someone clue me in as to why grouping related functions in a file with nothing but a namespace is strictly better than those same related functions grouped as members of a class? It doesn't have to be Larry or Derick, because even though they have expressed this view, I am aware they are not the only ones whom hold it. Anyone who can shed some light on this perspective is welcome to comment.

Cheers,
Bilge


It isn't i= mplicitly better, but if PHP had proper support for autoloading functions, = I would at least consider them equivalent when all the functions/methods ar= e public.

My primary language is C++, where the distinction is even b= lurrier since both static class members and namespace members are accessed = with '::'. For example, X::Y() could be a namespaced f= unction or a static method, and it doesn't actually matter which it is = under the hood since they are functionally identical.

In PHP, however= , putting all your functions in a namespace is less performant than using s= tatic classes. For instance, if you have ten functions.php fil= es each for a separate namespace, Composer will load all ten for every sing= le request, regardless of whether they are used. Additionally, if you insta= ll a Composer package that registers some functions, those will also be loa= ded for every request.

Cheers,

Lanre

--00000000000090bb3b061d04459d--