Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123888 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 DACD21ADB06 for ; Wed, 26 Jun 2024 20:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719433209; bh=+6o8aR32a5wUbLm1mH766JoZRiEdGTC4eu3GLqBdJrM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Iop/6CIhrIXu3LShTuodu300VhueqsgyBYdzC84YYjkX/4xfY5VRyg3tGtutzZlcA gyZr+PLaFLxsQ4YG2bp431bVGPOZTt7l6lmD6wsItAp3sJxv7njSa1H0S62M0QtwGi g3ya2KgbHLh5QEDXCleBTmG9a81Q26Jhy8WZfnLEmR9atsx3U75OmVBDSlPW5PSmLG wrSb2VaD9faAHFkJhjYeOJqi+wJAMw3MaSwSgXQ7KcoN8sOFds7nHlR+pvUw4Y7Voh VcZhdXeC31ggtgc9sTPmKXuO4Jc3m/UFdS4CiDw+ERPYjGom9bwjBYMorTTH4OtAdR VotGT4UMax6PQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A76F31806DB for ; Wed, 26 Jun 2024 20:20:06 +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-vk1-f176.google.com (mail-vk1-f176.google.com [209.85.221.176]) (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 ; Wed, 26 Jun 2024 20:20:04 +0000 (UTC) Received: by mail-vk1-f176.google.com with SMTP id 71dfb90a1353d-4ef662a4725so1891812e0c.0 for ; Wed, 26 Jun 2024 13:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719433126; x=1720037926; 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=7pdGEZu8mKpECR1AX6Cb4fyhxg0r316DJ6XpPD6ai+w=; b=Hl6Ep0BWwkAK54pMl/9elYzZPaFTxtR0vAJ1yF+rIEBidTeohy4wJAtPtnsHP8Pi1i 73x7c+0vx3NGv4KA65YSbR6bepG71iGW+w36MNrzGI3fyk6aRpX+4TEN+p3upXgEF0yF Inxduaecjd3ZPQ7SgIgtu1ZzD91RVIXdlMocoKi6qcFB8oG5kgxfvRHxujQEF6sKXjIb XRvJPj3eZ4dswW3leMnhl++Ls1kg5x10oevKr2uPC7bRwwGrCKYHTUH7QvmxN/OHBMB5 ua70A8ebDHffKY6AjofXL7YQm5klsOCB5RzoeOvyUyrFjVIioG+Cg94XSk5U7r174HmK cxbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719433126; x=1720037926; 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=7pdGEZu8mKpECR1AX6Cb4fyhxg0r316DJ6XpPD6ai+w=; b=YvO1LjCorr/RKkBn2l7Z4tJzM+oV7EMZR6jmf8gLcC4jspfuSdxB0hPEJhSaqCvxMH lG9fMr6g/s2ZyaWjxAWRF/D1/fBYebR9Xwe9bfSl09my9upGFSNgjn5gLCxRKMVnqyMl xSkdyDE/ZennF5McvRMcfnzw9H6C1gw3+Vvu7KM06eCEk7oiu05L/IdTfPURNbZw86yR FqnjPg1hdC303nNdI8aeL9dS/h+iKvphRqm+L0imZdNvbqu1V6NUHTfAEthQ9CtYJOq8 3AUxAvMM7fTqa9PF/lEXm1HUskFrCxTOaMljeuIz0Y+Q7wzK0RLEK1El8Cj2yBFn7a4i J2TQ== X-Gm-Message-State: AOJu0YwuAxzFMouAqA1jRyHm+P8PaoYdTfHm+8X3tYf5PgNooirdI3Ty 5PvMQaumo66dJcYrJqyonV899ZCUxHtrQ8FPw8UZab0XR0RT4RD7qzwLG/JRpicwJcqMD6n7Nok NlxtEy7AjrD8Oc+Cvatev56HnaoBquI/hnqc= X-Google-Smtp-Source: AGHT+IFW/4QJt0AwlNAHDiU1qtLlICarI/N6ksMp4QlY1w/1EP7Y4rTB4lLCIWkn1Q5zkPsD6l+qQ8lUNeE9j6PAPX0= X-Received: by 2002:a05:6122:3c4f:b0:4ef:58d4:70f5 with SMTP id 71dfb90a1353d-4ef6a5a3774mr10621475e0c.2.1719433125977; Wed, 26 Jun 2024 13:18:45 -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> <0b665744-b146-4276-9c55-e71717d974fd@app.fastmail.com> In-Reply-To: <0b665744-b146-4276-9c55-e71717d974fd@app.fastmail.com> Date: Wed, 26 Jun 2024 14:18:37 -0600 Message-ID: Subject: Re: [PHP-DEV] [RFC] Static class To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000b0644c061bd0b80a" From: lnearwaju@gmail.com (Lanre) --000000000000b0644c061bd0b80a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable That isn't a top post, look again.And I am not referring to packages,rather to the ability to define functions that aren't exposed to the users of a library. C doesn't have packages either yet this is possible in it. And marking it as internal is not the same thing at all. I am not going to argue about why a developer would use static methods and whether that is actually a sign that the developer doesn't understand OOP. But I do want to get this straight. Instead of actually hiding the function, your idea is to mark it with @internal (via PHPDoc)? To you, that solves the problem? On Wed, Jun 26, 2024 at 1:46=E2=80=AFPM Larry Garfield wrote: > 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 wou= ld > 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 t= o > 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 ide= al > 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 cryin= g > 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 develope= r > doesn't actually understand OOP and is just writing procedural code with > more steps. The other 10% are either named constructors or cases that ca= n > now be replaced with attributes. > > --Larry Garfield > --000000000000b0644c061bd0b80a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
That isn't a top post, look again.And I am not referri= ng to packages,rather=C2=A0to the ability to define functions that aren'= ;t exposed to the users of a library. C doesn't have packages either ye= t this is possible in it. And marking it as internal is not the same thing = at all. I am not going to argue=C2=A0about why a developer would use static= methods and whether that is actually a sign that the developer doesn't= understand OOP. But I do want to get this straight.=C2=A0 Instead of actua= lly hiding the function, your idea is to mark it with=C2=A0@internal (via P= HPDoc)? To you, that solves the problem?

On Wed, Jun 26, 2024 at 1:46=E2=80= =AFPM Larry Garfield <larry@ga= rfieldtech.com> wrote:
On Wed, Jun 26, 2024, at 6:05 PM, Lanre wrote:
> In JavaScript/Typescript, we can declare functions that are local to <= br> > the current file by not exporting them. In C/C++ this is achieved by <= br> > simply writing the function in the implementation file as opposed to <= br> > 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 <= br> > scenarios where hiding non-API functions might be necessary? I'm <= br> > curious why you keep returning to namespaced functions when they don&#= 39;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-l= evel scope.=C2=A0 A private static method is private not to a file or packa= ge, but to that class.=C2=A0 (The class and file usually correlate in pract= ice, but there's nothing in the language that mandates that.)=C2=A0 I w= ould love to have a concept of packages that we could use for scope, as mos= t more recent languages have concluded that is the correct level at which t= o enforce visibility, NOT objects/classes.=C2=A0 That's an entirely sep= arate question, however.

For marking a function as "package private", the same way you wou= ld for a package-private class today: @internal docblock.=C2=A0 It's no= t ideal (the ideal would require packages), but it still communicates the i= ntent, has worked for classes for 15 years at least, and signals "if y= ou use this class/function/thing and it breaks later, that's on you, do= n't come crying to me."

(ab)using static classes to emulate a pseudo-single-class-package is... abu= sing static.=C2=A0

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 wit= h more steps.=C2=A0 The other 10% are either named constructors or cases th= at can now be replaced with attributes.

--Larry Garfield
--000000000000b0644c061bd0b80a--