Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123889 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 02D071A009C for <internals@lists.php.net>; Wed, 26 Jun 2024 20:25:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719433635; bh=ZGgCH71v+taNMZNxzhgQemuRrowjcyPbVFzSxGBPqgg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VvxTYoP+ydN6PGVukzrPu/WGNYEED0Wdh1+oBljDOcxGFjOJwoQ2pSHqhf87wwJ9n B92YK2xxdZ2A/2lLiqV5ppDJnnRl5vVfv60HRN/gxjzCCN1uDkK63XF4lSlbDSO1ZN IN2lR5Kb9m6WSM5VUq47Jtsdz7lTZb5awZ4jQ2lJAlFUKC5FUxS1whfraQr/osgTGh w+15G6+iu++zd5bj3aUUG0dORIsNDR8rfwiBtYiqRQJS/sXCDanOBr9YWWSdV6oWDg 9GLK4YgIDfgw/cFK3RmNe7k4/sxHPGBU49GVbKXONk0s3NTSOKJ97hjLs16Xf8I9Q5 cWF9j/Jh7LH2Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E9CE91807F2 for <internals@lists.php.net>; Wed, 26 Jun 2024 20:27:12 +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: <lnearwaju@gmail.com> Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) (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 20:27:10 +0000 (UTC) Received: by mail-vk1-f172.google.com with SMTP id 71dfb90a1353d-4ef31ac8b80so2409339e0c.3 for <internals@lists.php.net>; Wed, 26 Jun 2024 13:25:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719433552; x=1720038352; 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=bpZ41L6xvFe6QyIjPmoVNFxmfZ3S+QQEUm8BUIDJTUg=; b=KlRPh9eZYjWALS3EJYktSRqMdjl2FGSCC6Y9v485xlNUGvsA3izD2/YjnDYmDoAjMv 3XdJRyNEkqUdiuWYgqanvwTuQ2fqsJ3PLsKOnU82x7FWHE6edEuDDV41HHKvuic2w3XV WDhTWKx+WDiem2eDhrYsH2377kO/uWNXSFjhwAEhApWhILXp+/PGMLXzSOxd+fBOH1HY wqKaSJtT8sNYBI++9HK6ed5uSr+fNywte4nYnF8PFvkmJC3X1VzKT7pT/fc9R4rdDTlT IO0eXoIz1rAzeIr89gRRH4ZCUntV6lkCpwQMV0TqfOLB8Ve7T2Hqu/nvhpcMbSMQl1ld HgcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719433552; x=1720038352; 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=bpZ41L6xvFe6QyIjPmoVNFxmfZ3S+QQEUm8BUIDJTUg=; b=w7ZT6lMt8fuAYA+dtfqF580L8mnqm04OcGnXA5bmtZn81sWcZoyVY/TvmzvwwoV/km X/RcU7Gch4luO/LsYsIRw1SXtEWIJLgmoJwDHe9fRT7AwyZ+lK+swh/WBw2QgP6sBaO4 xOT1/Z6K4wNy5iI8BCdKfMKBQFmOIR/BAUY6St9ISV/KrBtEmKo53v6MCsme/lBhMivd zJoNY8EdlbLN2XhGNz/JbPUhhoQk9cL4M5ZQ0aiSI4WPBOxRTCQrGFrA3J+uYcG/Iwog Yg8E1bKiYbKdtfi2jqa0MdBuwG2SYRpO9TdE3frc/i8Bs+XenmXurZFTmZSk5XzIj6lk 5Odw== X-Gm-Message-State: AOJu0YwMroO+RcTGVGijefcMooljzsTd7ZYdhljptzkeofFHyyE5Frmj npB7Y/tL2QCqaIRE0WdGj/ASD0LBcuaAbX83m267nabtYzykKV2GuLuLieXpdP48ITJIvBro0+n WmPPEM5HvUvh8HEGFbMwQ1Az2Dnk= X-Google-Smtp-Source: AGHT+IFm9QDW3WzHeDKDvAHOJu55DHW0UMsYIBNInHXxtVHCKImTyHgmZ/8mUIDg7/491DFUhsvtrCegWb+DXMtBwj8= X-Received: by 2002:a05:6122:411d:b0:4e4:eda9:ec32 with SMTP id 71dfb90a1353d-4ef6d88e925mr9643926e0c.10.1719433552155; Wed, 26 Jun 2024 13:25:52 -0700 (PDT) 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 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> <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:25:43 -0600 Message-ID: <CAM7F2-8ywx_MJvcpq52LcoHT2WOv30wQuD5TtBKBO1L6s0B9iw@mail.gmail.com> Subject: Re: [PHP-DEV] [RFC] Static class To: Larry Garfield <larry@garfieldtech.com> Cc: php internals <internals@lists.php.net> Content-Type: multipart/alternative; boundary="000000000000175e27061bd0d27f" From: lnearwaju@gmail.com (Lanre) --000000000000175e27061bd0d27f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Also I specifically said "we can declare functions that are local to the current file by not exporting them.", Where did you get "package private" from? On Wed, Jun 26, 2024 at 1:46=E2=80=AFPM Larry Garfield <larry@garfieldtech.= com> 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 > --000000000000175e27061bd0d27f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Also I specifically said "we can declare functions th= at are local to=C2=A0the current file by not exporting them.", Where d= id you get "package private" from?=C2=A0</div><br><div class=3D"g= mail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, Jun 26, 2024 at 1= :46=E2=80=AFPM Larry Garfield <<a href=3D"mailto:larry@garfieldtech.com"= >larry@garfieldtech.com</a>> wrote:<br></div><blockquote class=3D"gmail_= quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,= 204);padding-left:1ex">On Wed, Jun 26, 2024, at 6:05 PM, Lanre wrote:<br> > 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 <br> > requires using private static methods, or else you incur the overhead = <br> > of creating an object for stateless functions. How do you propose <br> > 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 <br> > fulfill the same role.<br> ><br> > Cheers,<br> > Lanre<br> <br> Please don't top-post.<br> <br> 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.<br> <br> 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."<br> <br> (ab)using static classes to emulate a pseudo-single-class-package is... abu= sing static.=C2=A0 <br> <br> 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.<br> <br> --Larry Garfield<br> </blockquote></div> --000000000000175e27061bd0d27f--