Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123621 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 E0F961A009C for ; Sat, 15 Jun 2024 17:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718473245; bh=aHFd0x58rc5tJI/951cIsRAvDDJRxJLdfDmxETkOGAc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SeUKjtfJtRcK3x/yaBNWkDRWo1n4OORM7LnDHEmo33qxghM56EwAQbwye0Hu88xeR qi7Gnf0tunUP1twif8YKg4pknEVHM6xbVXeQBUMJ1gAJECXpR24awkmPYmGfw6sWZW kPOZiCvdkVZo11Pn5eFQgMdsOn6dxQTf4/94NIl1g2upywyZXM1QEvOhpT1FLJaRS+ N03eJYD7F5HqC0kEiftCW+dcHnklmm5R2LI0CJCS7kpcLOMJMmkDi7bPIF9637aIgM na0lvHfZPUD7OZVP9RcYX0bLV/rkIId/FH7uBeRMJf3mR/zKawBdUU6xVWc8Td4sQg DVV2oUKuhnnoQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 27ECB1807EB for ; Sat, 15 Jun 2024 17:40:44 +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,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 ; Sat, 15 Jun 2024 17:40:43 +0000 (UTC) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-42249a4f9e4so22138745e9.2 for ; Sat, 15 Jun 2024 10:39:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718473172; x=1719077972; 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=aHFd0x58rc5tJI/951cIsRAvDDJRxJLdfDmxETkOGAc=; b=B4+CN4Sco7h6pDM8EIREEPupsx4kosya64186JvFHrA/Tuik2R9W04Y+nvkaO2mi5I V/MwkJifjfp/53gVbWEpzyhn0sbBL/aCRbhanJuBA1KiNeOmbDt18/+ffFJy8wmxFEGj kOODxAesGLAODw0dYunFBc0MpRLIrCQl1bcrdD4TLOs0oJ2irwNaINw0ShcjF7MwXd5b 9B1fMaAZF/BhHG7U1oSvnbW6KHl+4HkqocL8sKDd6ZcSlExdIfuH06vifwznDv1Y9Ryb PnxavU60Nq9UCA3OO7nPn7bhaymwEyrAx5WMmE6EoV5+CCtN6G4dKmxU4V3c/yL300bs h9Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718473172; x=1719077972; 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=aHFd0x58rc5tJI/951cIsRAvDDJRxJLdfDmxETkOGAc=; b=gV7V6V8u1OWFMJvREvjjPRTcYGM6QGjKI/tDcbkRztntBzdlAAqxoNeSkOHDn39KIQ 9dDouWqKcea+r/1CEsJZldK+Vm8n3Nbs9w3RudnBpQeRL4gzDbvBrXxKyBHGIYtwK1ig ARawNIJrj2+PGoa1+AP75/qLROx5Hjsu5ymds5UthT+XFRpRUmt4x/gq77i2rDyg9M2V ksTdel68/uMfSA3V4EjJiXv7C+VY/MVZh2l6sCtt/lJxw+AYfJpmdt2CsI6PaNUvdATJ 96IIchjV3uBcsg/Hzm+D4IeIohkJ89Y5Mhd/aWfjrkRVvOxH2FF2kAyN3TIt5J389+lq GGSw== X-Gm-Message-State: AOJu0YxTAA2uQuqa2ARBW4l/niP6WlieDzsH/W4tpCK++OzPf2d+Ww44 vdlI3AjDpgbIHOsGXY72djPwXHsHi58jPnJtT4TvI8XR0r6Oy+dIaDbY0WrGXWX+USKpKAAA8eC MHunwQ+++jJ9bOCxDviP7NTd+eloD1IWTAA== X-Google-Smtp-Source: AGHT+IEMNX+m+VY1Z3dxkIgrYlmq8cJPq/kR34lHIhmXNJ2cyPIgO9pMXW/Y8wZbCI97Zscgbhs5kilu7y80JmSUamE= X-Received: by 2002:a05:600c:4887:b0:422:77d0:a3d5 with SMTP id 5b1f17b1804b1-42304854f19mr52969195e9.36.1718473171538; Sat, 15 Jun 2024 10:39:31 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <0cf69a14-f1b5-4077-9d91-d7b579485eec@scriptfusion.com> <936e1aa3-48cc-4552-9f68-676ebcdeb596@rwec.co.uk> <1fc2f2d0-718f-45ec-8968-b66a1bde686e@scriptfusion.com> In-Reply-To: Date: Sat, 15 Jun 2024 20:39:20 +0300 Message-ID: Subject: Re: [PHP-DEV] Static class To: Bilge Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000f21b1e061af13601" From: udaltsov.valentin@gmail.com (Valentin Udaltsov) --000000000000f21b1e061af13601 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, 15 June, 2024=E2=80=AFat 19:21, Bilge wrot= e: > On 15/06/2024 16:58, Rowan Tommins [IMSoP] wrote: > > Common arguments against: > > > > - Static properties are a form of global state, and that's something > > widely advised against > > Correct, but a static class does not need to have any state. Indeed, I > cannot think of an instance where I (personally) have needed state in a > static class. If this ever becomes a point of contention (though I doubt > it would), we could even consider prohibiting state in static classes, > locking it down completely to just methods. A draconian option, but an > option nonetheless. > > > - Static classes without any properties would be the same as putting > > functions and constants in a namespace, which we can already do > > You already provided a counter-point to this; we can't autoload > functions. Besides, there may be good reason (organizationally) to group > sets of static functionality together (in a class) rather than having > them as free-standing functions only so grouped in a file (which does > not necessarily imply the same degree of cohesion). > > >> rather than fall back on the opinions of many who are mostly absent > >> among those polled nine years ago, I'd rather get a sense of the > >> current sentiment of those present today. > > > > This line of thinking always makes me uneasy. It lends undue weight to > > *who* made decisions, and not enough to *why*. > > Meaning no disrespect to anyone whom was participating nine years ago (I > have nothing but respect for those whom came before), I really don't > care _who_ fielded opinions or decisions, my point was simple and > singular: that even if an opinion was valid back then, if nobody were to > uphold it today, it wouldn't carry any weight now. I think enough time > has passed that gauging the sentiment of today is valid and worthwhile, > especially if it has shifted (and we cannot know without asking). > > Cheers, > Bilge > Hi! > Static classes without any properties would be the same as putting > functions and constants in a namespace, which we can already do In addition to the absence of autoloading, this is also not correct because PHP does not have internal/private functions. Very often I use functions for really simple things like `array_flatten` (and register them via composer.json.autoload.files). But when the function requires decomposition to smaller ones, I switch to a static class with one public and some private static methods. I tend to support this idea, because it makes intent more expressive and allows to get rid of `private function __construct() {}` visual debt. I also agree that static implies final. This could be later changed without breaking BC. Good luck, Bilge! --=20 Valentin Udaltsov --000000000000f21b1e061af13601 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sat, 15 June, 2024=E2=80=AFat 19:21, B= ilge <bilge@scriptfusion.com> wrote:
On 15/06/2024 16:58, Rowan Tommins [IMSoP] wrote:<= br> > Common arguments against:
>
> - Static properties are a form of global state, and that's somethi= ng
> widely advised against

Correct, but a static class does not need to have any state. Indeed, I
cannot think of an instance where I (personally) have needed state in a static class. If this ever becomes a point of contention (though I doubt it would), we could even consider prohibiting state in static classes,
locking it down completely to just methods. A draconian option, but an
option nonetheless.

> - Static classes without any properties would be the same as putting <= br> > functions and constants in a namespace, which we can already do

You already provided a counter-point to this; we can't autoload
functions. Besides, there may be good reason (organizationally) to group sets of static functionality together (in a class) rather than having
them as free-standing functions only so grouped in a file (which does
not necessarily imply the same degree of cohesion).

>> rather than fall back on the opinions of many who are mostly absen= t
>> among those polled nine years ago, I'd rather get a sense of t= he
>> current sentiment of those present today.
>
> This line of thinking always makes me uneasy. It lends undue weight to=
> *who* made decisions, and not enough to *why*.

Meaning no disrespect to anyone whom was participating nine years ago (I have nothing but respect for those whom came before), I really don't care _who_ fielded opinions or decisions, my point was simple and
singular: that even if an opinion was valid back then, if nobody were to uphold it today, it wouldn't carry any weight now. I think enough time =
has passed that gauging the sentiment of today is valid and worthwhile, especially if it has shifted (and we cannot know without asking).

Cheers,
Bilge



--000000000000f21b1e061af13601--