Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:123878
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 0DB9C1ADCCB
	for <internals@lists.php.net>; Wed, 26 Jun 2024 18:21:34 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
	t=1719426171; bh=OkoW47f6wPU93POCAWg3vTUIAOqyxT8I9b7qZS/TdiY=;
	h=In-Reply-To:References:Date:From:To:Subject:From;
	b=DbX2L2U5AIFXxHLRx86pAEkDDjnBv5wwCfEjmmnjhGQPl0R8UIULVLWbrxHdSZH9x
	 txLtANLv2NaqgVTo+cNRrjxS+WFHO80aRw6JKSO4TJok3f8VjSHqNOgviyMW6VbYzU
	 iuNc69st9MrbxQimHO0cj/u5akowRoWfgTZFQ+E0fY17sEBIEcNK9mGrY9kO1G0bsM
	 0HCyZZpnErlJSx4WZla+TjaSMpORQOGWmC+lJNO/9biFy6IJ3taGrdYittWmFBiQIf
	 EKv6Cp2vnsfMWCKfH9fjevpdtF4VGRQQVYKvTMb3Znx8Pu3VrJehTVhQ0D/vOrlakJ
	 twZr4pXLW3VaQ==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id 8D282180A0B
	for <internals@lists.php.net>; Wed, 26 Jun 2024 18:22:49 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW,
	SPF_HELO_PASS,SPF_NONE,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: <larry@garfieldtech.com>
Received: from wfout8-smtp.messagingengine.com (wfout8-smtp.messagingengine.com [64.147.123.151])
	(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 <internals@lists.php.net>; Wed, 26 Jun 2024 18:22:45 +0000 (UTC)
Received: from compute1.internal (compute1.nyi.internal [10.202.2.41])
	by mailfout.west.internal (Postfix) with ESMTP id 204F01C00065
	for <internals@lists.php.net>; Wed, 26 Jun 2024 14:21:27 -0400 (EDT)
Received: from imap50 ([10.202.2.100])
  by compute1.internal (MEProxy); Wed, 26 Jun 2024 14:21:27 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
	garfieldtech.com; h=cc:content-type:content-type:date:date:from
	:from:in-reply-to:in-reply-to:message-id:mime-version:references
	:reply-to:subject:subject:to:to; s=fm2; t=1719426086; x=
	1719512486; bh=7U1Nn/dMa98oRBIjV+pnJo6Vab7vdmiA0/QlbGMuw5E=; b=V
	G2emNaTyuWWb5qZa7IBCoeB3+w6TpguBCR69xzyB6YD2f2LhL6jYvYRjlM/n9sDJ
	TouUQwzEV9OYNLCBYPHDNUbTISkrnK4/kuYtupTSDtVg4yj15gRb5NbrVGGGamEl
	TjguXjDjftx7ojJ+keAhRQJsRvkR9HmlX0aKNJG/rvVpO/LvPnGGTJic7LWsCVQl
	roCZv+5TbMjJ5lAjKVgN8yqgHXUoLJ7rbmteg+TWT+Pyn1XsHumRTQOGiY9pY5TJ
	1zJvaLE+lU9x0pDW014AYGXYQmdLwfOTgXvNqu/TTosGDbNrYFEYPQC+wDCmF7HB
	pjhi2fjM1i43HGT4x/PJA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
	messagingengine.com; h=cc:content-type:content-type:date:date
	:feedback-id:feedback-id:from:from:in-reply-to:in-reply-to
	:message-id:mime-version:references:reply-to:subject:subject:to
	:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=
	fm2; t=1719426086; x=1719512486; bh=7U1Nn/dMa98oRBIjV+pnJo6Vab7v
	dmiA0/QlbGMuw5E=; b=TOLvhVKpLsb3x4VLVTn7jbMznl5ehxcNo22ldJgExnvO
	9r0FZROmoP+V+GtguQhTqXG25iKPZEuv3pQgFdMy9pgOJZZn3iIGp+HXzw7OpANx
	iMkho5afyRjODSazijeKocEQ3mm5gjxnNB4pHVhyz6cLBsOX/gOraDLhSfAN2z5b
	vFEKWO0l+fcyXxW0kDxui24755UdTann+pmS2UuvUAcIOZXNNlh86O8M2iyxTOb9
	nYHHOoWoIF6S8oyY5gMzkPfw5T360QTZQmcITtFXiX1/LUY5YkHEsnE6T6Pyg187
	kyCSK3rwOW5w2NBS06Buo1Jai6RHGpVw74Q81CJGtQ==
X-ME-Sender: <xms:Jlx8ZkuNivszMsxz7ZSA47hkqqGrdmfDTDXljS0v_ump0DsuB0wTPA>
    <xme:Jlx8ZhenCShVAux33Lzo0LR54PVNZKOTG0PY4afoGWVaPfh6XE3C0rr5LzZL6_KaR
    SYZrmM1Q_OjzQ>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtddvgdduvdegucetufdoteggodetrfdotf
    fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
    uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne
    cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr
    rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh
    hmqeenucggtffrrghtthgvrhhnpeevveehgedtgfevudfgudeftdfhheeugeeiieekiedt
    ffeiiedvveekvddvieevvdenucffohhmrghinhepthhhvghmrdhinhgtnecuvehluhhsth
    gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhf
    ihgvlhguthgvtghhrdgtohhm
X-ME-Proxy: <xmx:Jlx8Zvwmz6qBaAfwA1fQt3ErYDeBboJk66zYYjWxp-Bb69l3bLaTdA>
    <xmx:Jlx8ZnNtbZTEF9jMUr7Mfn_XNbcfDebg-3fA8HaIg9IMwgJxVXbvRg>
    <xmx:Jlx8Zk-wNF-C_pOLWYWWnuILHIgjsrP_yJyhCwl_tHB4IKc1GYEBRg>
    <xmx:Jlx8ZvWnkGtdj_xJOnhEc0rc__g2Jycxu6QJvM44BZIh8zA7eN-pZg>
    <xmx:Jlx8ZtIFHQdz_-dyDh2TC83F6ISoX6BI9fB_5soT0p8XuI0APk8qDrXF>
Feedback-ID: i8414410d:Fastmail
Received: by mailuser.nyi.internal (Postfix, from userid 501)
	id 7B1861700093; Wed, 26 Jun 2024 14:21:26 -0400 (EDT)
X-Mailer: MessagingEngine.com Webmail Interface
User-Agent: Cyrus-JMAP/3.11.0-alpha0-538-g1508afaa2-fm-20240616.001-g1508afaa
Precedence: bulk
list-help: <mailto:internals+help@lists.php.net
list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net>
list-post: <mailto:internals@lists.php.net>
List-Id: internals.lists.php.net
MIME-Version: 1.0
Message-ID: <0b665744-b146-4276-9c55-e71717d974fd@app.fastmail.com>
In-Reply-To: 
 <CAM7F2--zTgD7ar7cXcX9xXf=5ZdLpz0tSVqUns1COonUKbZg9Q@mail.gmail.com>
References: <eb3f59cc-3ed8-461a-a3a4-f6ba10ed31e1@scriptfusion.com>
 <ef0c3617-6757-45a1-a485-3f7c197fd599@app.fastmail.com>
 <4596aa73-cfd4-2292-7191-2839a5bab695@php.net>
 <CAM7F2--zTgD7ar7cXcX9xXf=5ZdLpz0tSVqUns1COonUKbZg9Q@mail.gmail.com>
Date: Wed, 26 Jun 2024 18:21:06 +0000
To: "php internals" <internals@lists.php.net>
Subject: Re: [PHP-DEV] [RFC] Static class
Content-Type: text/plain
From: larry@garfieldtech.com ("Larry Garfield")

On Wed, Jun 26, 2024, at 6:05 PM, Lanre wrote:
> In JavaScript/Typescript, we can declare functions that are local to 
> the current file by not exporting them. In C/C++ this is achieved by 
> simply writing the function in the implementation file as opposed to 
> the header. However, achieving a similar level of privacy in PHP 
> requires using private static methods, or else you incur the overhead 
> of creating an object for stateless functions. How do you propose 
> handling such cases using namespaced functions? Can you think of any 
> scenarios where hiding non-API functions might be necessary? I'm 
> curious why you keep returning to namespaced functions when they don't 
> fulfill the same role.
>
> Cheers,
> Lanre

Please don't top-post.

PHP has no concept of packages at present, and thus no concept of package-level scope.  A private static method is private not to a file or package, but to that class.  (The class and file usually correlate in practice, but there's nothing in the language that mandates that.)  I would love to have a concept of packages that we could use for scope, as most more recent languages have concluded that is the correct level at which to enforce visibility, NOT objects/classes.  That's an entirely separate question, however.

For marking a function as "package private", the same way you would for a package-private class today: @internal docblock.  It's not ideal (the ideal would require packages), but it still communicates the intent, has worked for classes for 15 years at least, and signals "if you use this class/function/thing and it breaks later, that's on you, don't come crying to me."

(ab)using static classes to emulate a pseudo-single-class-package is... abusing static.  

To be blunt, 90% of uses of static methods in PHP are a sign the developer doesn't actually understand OOP and is just writing procedural code with more steps.  The other 10% are either named constructors or cases that can now be replaced with attributes.

--Larry Garfield