Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122805 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 80FB81A009C for ; Fri, 29 Mar 2024 15:50:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1711727437; bh=H2NK0QMx1nlB84oIBlBLkjQx69LUfsjSIZmm51KYf2U=; h=In-Reply-To:References:Date:From:To:Subject:From; b=ZQ6VaPUOsQ+7T/UrSnO+Zm92dZVRUvuy80Q/Ki4C9WhF/eJRVW8T6GmNwV6UHekoD dV70uETvJY0LM0MZ8K3dW6/4F9Fa6dkJPjcQzEE6VZyS85LDqxR/SLMqekC+es6c8s G96Zqtwt8h80/ORI8AsBXaSRTzS/IPWGnYntGXFm5HimI+Zm8mqzTrPjzjreazQYvf rPvU1Dh8JvIG8iAHA621P+ME9aSCxUYR982C5wGN2doaNGxv6JayY/Rr/R8jIJMp5w 8UM5vDV8VR92wmXaRp3iNDYvHZ/5MgIPgMCjzAs/0BG0KyrVOrNxHO7Wl8zZvNnUd/ WAL1GhQYojAOw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 006E3180609 for ; Fri, 29 Mar 2024 15:50:36 +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=1.4 required=5.0 tests=BAYES_50,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (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, 29 Mar 2024 15:50:35 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 712603200A0F for ; Fri, 29 Mar 2024 11:50:08 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Fri, 29 Mar 2024 11:50:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=1711727407; x=1711813807; bh=EW5RNLD/EgydcwtG/3jSs fA80UDXjpZvbYMBif5B0mE=; b=GrzzkByxvh4LwYpV9xKpLfYlgnLzn+J+F/eu1 taDDN8a9VzihPvW1rQ92nTzG/OPtSyalv2BgCE8JKFcFg7aO8CXLQSrtkejKOT9h N2upCZz2EGwWUxlZEYBShx6wJ/6q58vsjMzpy8xu3G97Yh4Ca2nglrQH0yqjsLzZ Dig4LASXiaFmmxomnRzcz3gN1r1THTmKnpliLE79qAexVfIqIPKCqtUjnUjSloP8 OE5ttxuzzAQvcqQJf8C19zuy/H3OLR0/V7ULEx5u7DL8Ep/VamUDXhrNsq00QJnI BaSSK5bpQIw7T8FAdkU3m+z0BOmnVF4POkpmp2a+rs/T+IzCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=1711727407; x= 1711813807; bh=EW5RNLD/EgydcwtG/3jSsfA80UDXjpZvbYMBif5B0mE=; b=g 0+kQ24jzv4DdrTMHZEzbs/vduAW+cPdIHCe8vIKfGV5CazMQt5urNmJ9eMFrC0aI xJxbz45qoqGdC0u24Xpvvig3VGOo+YjfH98Ypy+w7DSvdWiUJeZsbKxonPTLxBBL yWwuhzqioRpdpF64ApZVyr+i7toef8lDgFkmSnCjUDzNn1KW7YCpkaPNf3GJoVr9 cYXguJIAZD333p/81wlAuq70x9XvUj1JrkiNqEym1K9vDDtZBdM0ENm+aQ1mF1tB s4BewROBJtgMv0HTzma/DjA6sipnXZjucV8kZtO9OdiyYy7BbWPe2DvBmLpaOI1A JHHsCNJisUwRfVPAuemKw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddvvddgkeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffeivddufedufefgveffueetveeiiedufedvudel heeivefgveethffftddvhedunecuffhomhgrihhnpehphhhprdhnvghtpdhpvggrkhgurd gtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep lhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 952341700093; Fri, 29 Mar 2024 11:50:07 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-333-gbfea15422e-fm-20240327.001-gbfea1542 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: Date: Fri, 29 Mar 2024 15:49:14 +0000 To: "php internals" Subject: Re: [PHP-DEV] [RFC] Invoke __callStatic when non-static public methods are called statically Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Fri, Mar 29, 2024, at 3:33 PM, =ED=95=98=EB=8A=98=EC=95=84=EB=B6=80=EC= =A7=80 wrote: > 2024=EB=85=84 3=EC=9B=94 29=EC=9D=BC (=EA=B8=88) =EC=98=A4=ED=9B=84 10= :21, Larry Garfield =EB=8B=98=EC=9D=B4 =EC=9E=91= =EC=84=B1: >> On Fri, Mar 29, 2024, at 2:39 AM, =ED=95=98=EB=8A=98=EC=95=84=EB=B6=80= =EC=A7=80 wrote: >> > Hello. >> > >> > I created a wiki for __callStatic related issues. >> > Please see: >> > https://wiki.php.net/rfc/complete_callstatc_magic >> > I look forward to your interest and advice. >>=20 >> I am firmly against this proposal. >>=20 >> I think my objection boils down to this line in the RFC: >>=20 >> > Of course, calling non-static methods in a static-like manner can b= e confusing, but in modern PHP, it has already become common practice.=20 >>=20 >> I would argue this statement is false. Calling non-static methods in= a static-like manner is confusing, which is why in modern PHP one shoul= d never do that, and respect that static and non-static methods exist in= a separate universe. Static methods are methods *on a type*. Non-stat= ic methods are methods *on an instance*. Those are not the same thing.[= 1] >>=20 >> It would be more accurate to say "calling non-static methods in a sta= tic-like manner is common *in Laravel*," where the badly-named "facades"= system serves as a poorly designed, hard to debug, hard to test, archai= c alternative to using dependency injection. While there may have once = been an argument that DI was "too hard" for simple cases a decade ago or= more (though even then I think it was a bade trade-off), the combinatio= n of auto-wiring DI Containers (which Laravel pioneered in PHP) and cons= tructor promotion (introduced in PHP 8.0, 3.5 years ago.) completely eli= minates those arguments. The level of effort to do actual DI today is t= rivially small, and the benefits over magic hidden globals are massive. >>=20 >> Laravel Facades are a relic of an older time best avoided, even in La= ravel projects. (I am far from the only person to argue this; many even= within Laravel's inner community make this argument.) >>=20 >> Adding features to the language that seemingly exist only to make tha= t particular buggy hack easier to do is a step backwards, and I would ar= gue harmful for the language. On the contrary, I would favor going the = other direction: Calling a static method as though it were non-static cu= rrently works, and I would support making that an error, to further emph= asize that static and non-static methods are not interchangeable. >>=20 >> [1] https://peakd.com/hive-168588/@crell/cutting-through-the-static >>=20 >> --Larry Garfield > > Thank you for your feedback. > I agree that static and non-static should be distinct, which is a give= n. > > There are a few points I'd like to make. > > First, my proposed RFC is not about allowing non-static methods to be=20 > used statically. Although all my examples use `::`, they internally=20 > operate on an instance. Inside `__callStatic`, an instance is created=20 > and used for operations. > > Second, as already possible through the `__callStatic` method,=20 > non-static methods can be called as if they were static (as mentioned,=20 > this does not mean they operate statically). For protected and private=20 > methods, the `__callStatic` function is invoked even for non-static=20 > methods. This might not be to everyone's liking, and to others, it=20 > might be a favorite feature. It might operate differently from the=20 > initial intention when `__callStatic` was introduced. However, I don't=20 > think this is necessarily a bad thing. Isn't it developers who bring t= o=20 > life ingenious ideas that were unforeseen? Developers also bring to life horrible monstrosities that are an afront = to all that is holy. I am a developer. It's what we do. :-) Especiall= y when VC money is involved. Not all "innovation" is good. > Third, as you can see from my examples, what I propose could be a=20 > solution to the current issues. Since it does not work for public=20 > methods while it does for protected and private ones, it has led to=20 > code becoming more obscure and layered through facade-like patterns.=20 > It's like taking a longer route because the road is blocked, or=20 > creating a dog door because the main door is closed. It simplifies a practice that should not be a practice in the first plac= e. That's not a net-win. > From the perspective of those who develop the PHP language itself, my=20 > proposal might not be appealing. However, I believe from the user's=20 > standpoint, my proposal could lead to more convenient and cleaner=20 > coding practices. Didn't PHP start as a language meant to be=20 > user-friendly?=20 I don't actually work on the PHP engine, I just write RFC text for other= people; I have ~25 years of experience writing user-space PHP. And no,= anything involving stealth globals via statics is the opposite of "more= convenient and cleaner." --Larry Garfield