Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122804 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 5B03B1A009C for ; Fri, 29 Mar 2024 15:33:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1711726451; bh=/oRZfJgYHaqV7K0BGY2fWischfAeLis0z5OUdDvXXO0=; h=References:In-Reply-To:From:Date:Subject:To:From; b=NAhWKPHKdTNOcmZAzcLUknQxTJInlyhbIFPiEGpnnleiX88dmRBZOy7VRaG1K3G23 aNTtMhVrzKug62lh2sY+St77Y+o7YHP6/UDEt3IX9MDV/96PjWWsSR3zniodnhHbk/ EF131qIlL1KkGtLTy9zQO9fQ58fg14CcHSbkGoihRw1NTp8jycbBu+WezLnUiXgJ3E RlNSnlAnNKXvlmLkrBQrgfXe2o6i901WWxkFstrNk48zeisoJWyGSd7X7BAMToobmt EC9gHPOpIxbM5l/GJzCeF2rCp2wtpQfhQki1Yjxafgw/wIquDKhB6KH0/zjsj17qAa EnDh/9+HyGAjg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 552F318006C for ; Fri, 29 Mar 2024 15:34:10 +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=2.1 required=5.0 tests=BAYES_50,BODY_8BITS, 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: No X-Envelope-From: Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (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:34:09 +0000 (UTC) Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-dd10ebcd702so2087551276.2 for ; Fri, 29 Mar 2024 08:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711726423; x=1712331223; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=ZPsd1Lsp7aYWczpjasCIchanYhEDgdULU1YFImjb/Cg=; b=l+eJ2OjZCDEgQKHRRD0aMh8i83AbQhnbdmJfIV9E68JQhYlrnekHssqavCV6sQESIS BF+K2YHifvFpc5DySTR7Ugcde8OHITYc4bXbtO3XlEjdW/lQhmUKqHeAJKw/fgmbsxOv iksMc/9U1s5Dgr1CoW1iUQiaxNZCqau5F+UeJkhLJhWL8F7TPCsYrXiwVD+w+aoswjzj nqc3d1daDP8FBsp1VtnNo4hsieFpZdV4xHYZC5MaajwTQBgFOcHoF1ciV2r/2jM0W1fn 0EdhlPFR/3c0UWMzvq9/g9k0oX5dRZ5YDVNj9Xy42e1MZhqu+6C4DA8vfwOqRlskcAVS UNgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711726423; x=1712331223; h=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=ZPsd1Lsp7aYWczpjasCIchanYhEDgdULU1YFImjb/Cg=; b=d+MkYFz04L1p7C6TjzWcMGWg9NDkybtBR1+dH+y/Un9mwsv1qFzKexpRsA4IuQCaEQ U1FmXmTnrn385mXTckKa19JRCZhBAam6+efdOvFUpESrm/a3X2JBZi6eSA3T0E8t9Sbx zDvRd3g1msCJkcLJCHWEvtSPUYpOfpjQ4XJTreXIgtKDQMhHR3hRsZoSW/0p1nbtVE0N tEyb9JIgDwRg/yrAVGh2tRkCYcL1CXqZpLtNNoP/NP6JXVPZOgd+iRf/QsgUBtn/brvZ GtgZiT29tXWyu8Jkm/Vic03xJmf4WT+Ic9vrh2v5PCis4T+NtHJXy+NbxA5LIHs6j8oF vufQ== X-Gm-Message-State: AOJu0Yyt7ASh80Xwwtl5x8+wo3ISL1ztUyXS41bbIdOHrgW+A//NXybl GDXU1Qwb4iIVj433Jfjg4fqug1XnzKFlINMAC3LFA0WBIZqdWgu9E2F5OTKP2X+CuJXoyamUUi7 O5rDiDZAokox8kW4vQBpavyg2SkIsrbWjoGHpc9I3 X-Google-Smtp-Source: AGHT+IEP1XB0JVCx67YI7THfZbCTLYmT614OhZJlRFLIuBfwAAw87TmmfpkKei1jyEx8AMS6MmA2a5B7NWD/uBV0SJY= X-Received: by 2002:a25:48c3:0:b0:dd1:44c1:350e with SMTP id v186-20020a2548c3000000b00dd144c1350emr2473474yba.34.1711726423049; Fri, 29 Mar 2024 08:33:43 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 29 Mar 2024 23:33:31 +0800 Message-ID: Subject: Re: [PHP-DEV] [RFC] Invoke __callStatic when non-static public methods are called statically To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000660f790614ce5d5e" From: daddyofsky@gmail.com (=?UTF-8?B?7ZWY64qY7JWE67aA7KeA?=) --000000000000660f790614ce5d5e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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. > > I am firmly against this proposal. > > I think my objection boils down to this line in the RFC: > > > Of course, calling non-static methods in a static-like manner can be > confusing, but in modern PHP, it has already become common practice. > > 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 should > never do that, and respect that static and non-static methods exist in a > separate universe. Static methods are methods *on a type*. Non-static > methods are methods *on an instance*. Those are not the same thing.[1] > > It would be more accurate to say "calling non-static methods in a > static-like manner is common *in Laravel*," where the badly-named "facade= s" > system serves as a poorly designed, hard to debug, hard to test, archaic > alternative to using dependency injection. While there may have once bee= n > 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 combination of > auto-wiring DI Containers (which Laravel pioneered in PHP) and constructo= r > promotion (introduced in PHP 8.0, 3.5 years ago.) completely eliminates > those arguments. The level of effort to do actual DI today is trivially > small, and the benefits over magic hidden globals are massive. > > Laravel Facades are a relic of an older time best avoided, even in Larave= l > projects. (I am far from the only person to argue this; many even within > Laravel's inner community make this argument.) > > Adding features to the language that seemingly exist only to make that > particular buggy hack easier to do is a step backwards, and I would argue > harmful for the language. On the contrary, I would favor going the other > direction: Calling a static method as though it were non-static currently > works, and I would support making that an error, to further emphasize tha= t > static and non-static methods are not interchangeable. > > [1] https://peakd.com/hive-168588/@crell/cutting-through-the-static > > --Larry Garfield > Thank you for your feedback. I agree that static and non-static should be distinct, which is a given. There are a few points I'd like to make. First, my proposed RFC is not about allowing non-static methods to be used statically. Although all my examples use `::`, they internally operate on an instance. Inside `__callStatic`, an instance is created and used for operations. Second, as already possible through the `__callStatic` method, non-static methods can be called as if they were static (as mentioned, this does not mean they operate statically). For protected and private methods, the `__callStatic` function is invoked even for non-static methods. This might not be to everyone's liking, and to others, it might be a favorite feature. It might operate differently from the initial intention when `__callStatic` was introduced. However, I don't think this is necessarily a bad thing. Isn't it developers who bring to life ingenious ideas that were unforeseen? Third, as you can see from my examples, what I propose could be a solution to the current issues. Since it does not work for public methods while it does for protected and private ones, it has led to code becoming more obscure and layered through facade-like patterns. It's like taking a longer route because the road is blocked, or creating a dog door because the main door is closed. From the perspective of those who develop the PHP language itself, my proposal might not be appealing. However, I believe from the user's standpoint, my proposal could lead to more convenient and cleaner coding practices. Didn't PHP start as a language meant to be user-friendly? Regards Daddyofsky --000000000000660f790614ce5d5e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
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 <larry@garfieldtech.com>=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_ma= gic
> I look forward to your interest and advice.

I am firmly against this proposal.

I think my objection boils down to this line in the RFC:

> Of course, calling non-static methods in a static-like manner can be c= onfusing, but in modern PHP, it has already become common practice.

I would argue this statement is false.=C2=A0 Calling non-static methods in = a static-like manner is confusing, which is why in modern PHP one should ne= ver do that, and respect that static and non-static methods exist in a sepa= rate universe.=C2=A0 Static methods are methods *on a type*.=C2=A0 Non-stat= ic methods are methods *on an instance*.=C2=A0 Those are not the same thing= .[1]

It would be more accurate to say "calling non-static methods in a stat= ic-like manner is common *in Laravel*," where the badly-named "fa= cades" system serves as a poorly designed, hard to debug, hard to test= , archaic alternative to using dependency injection.=C2=A0 While there may = have once been an argument that DI was "too hard" for simple case= s a decade ago or more (though even then I think it was a bade trade-off), = the combination of auto-wiring DI Containers (which Laravel pioneered in PH= P) and constructor promotion (introduced in PHP 8.0, 3.5 years ago.) comple= tely eliminates those arguments.=C2=A0 The level of effort to do actual DI = today is trivially small, and the benefits over magic hidden globals are ma= ssive.

Laravel Facades are a relic of an older time best avoided, even in Laravel = projects.=C2=A0 (I am far from the only person to argue this; many even wit= hin Laravel's inner community make this argument.)

Adding features to the language that seemingly exist only to make that part= icular buggy hack easier to do is a step backwards, and I would argue harmf= ul for the language.=C2=A0 On the contrary, I would favor going the other d= irection: Calling a static method as though it were non-static currently wo= rks, and I would support making that an error, to further emphasize that st= atic and non-static methods are not interchangeable.

[1] https://peakd.com/hive-168588/@cr= ell/cutting-through-the-static

--Larry Garfield

Thank you for you= r feedback.
I agree that static and non-static should be distinct= , which is a given.

There are a few points I'd like to make.
First, my proposed RFC is not about allowing non-static methods to be used=20 statically. Although all my examples use `::`, they internally operate=20 on an instance. Inside `__callStatic`, an instance is created and used=20 for operations.

Second, as already possible through the=20 `__callStatic` method, non-static methods can be called as if they were=20 static (as mentioned, this does not mean they operate statically). For=20 protected and private methods, the `__callStatic` function is invoked=20 even for non-static methods. This might not be to everyone's liking, an= d to others, it might be a favorite feature. It might operate differently from the initial intention when `__callStatic` was introduced. However, I don't think this is necessarily a bad thing. Isn't it developers= who=20 bring to life ingenious ideas that were unforeseen?

Third, as=20 you can see from my examples, what I propose could be a solution to the=20 current issues. Since it does not work for public methods while it does=20 for protected and private ones, it has led to code becoming more obscure and layered through facade-like patterns. It's like taking a longer=20 route because the road is blocked, or creating a dog door because the=20 main door is closed.

From the perspective of those who develop the P= HP language itself, my proposal might not be appealing. However, I=20 believe from the user's standpoint, my proposal could lead to more=20 convenient and cleaner coding practices. Didn't PHP start as a language= =20 meant to be user-friendly?

Regards
Daddyof= sky
=C2=A0
--000000000000660f790614ce5d5e--