Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122802 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 9BCCA1A009C for ; Fri, 29 Mar 2024 10:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1711709058; bh=KC9mboZ+SvDwEgPIBlZqSnzi8rzNN0/4UJfEL7i6LUg=; h=References:In-Reply-To:From:Date:Subject:To:From; b=hU4QruzcWCt5umhU9U3Hhc9Ts3F6QO0JBfgNzkkhDCaue1PvmuReSYtr1g0IRwA6E xL0DPSSDlHQulW0X0gD1OeMn9qh3GRor+e0Iu5l2egK68Rq9EW11EW5Uc1bxSqKOdg azqYVdItLG4C7f1a/MZ3Gv2YDE8d/xDyWhAi9atWN7reduP3cqpln9mzUALhZPefiS B1Zfx4g4IcYWydD1nN6LnXxPs/DI1no/taOtwm4Jz/4SN6kE7foi0aNmWmxp4iaBAr Qa7xpXAzRmAv1vfBuUWgT5BYoQETLWLkzVd/zh9B66VSFXML4Adri7klzmwQCUp0pg 6B44v9rMgo1fg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 26F93180699 for ; Fri, 29 Mar 2024 10:44:17 +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_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-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (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 10:44:16 +0000 (UTC) Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-6143fe736d9so4710767b3.2 for ; Fri, 29 Mar 2024 03:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711709030; x=1712313830; 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=KC9mboZ+SvDwEgPIBlZqSnzi8rzNN0/4UJfEL7i6LUg=; b=hDBrrhehZcGF/XFw/YIF8y/pn3J37HjX/EVh+AP6y1AUgegb//m30IOixL7+4q/E36 h46o8dPRrJQYldjlgZsCWVhCfxcokMz3NObsHitmrhyfzfqrB1H1h28FwCR0AZtjfyj0 BhyrSBJEYctW5JGxgLqfayxx9x4JwvOBy6HRUzapt6C90y5GWxttZzQRF6JgTTsROcP0 taydmh5y4EgiNuuHMz6xMAvc8z5U3Qrp+/TZXNYl0uh/aoeKW4KevkNcYpyVBK6kZnUt m8JXeV5dNqqSsufd5aoEaDGwVdV2S7PtqfRsxaU/LzoISeFHBJ5tLQIJtm+q7/sBAsP5 FhjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711709030; x=1712313830; 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=KC9mboZ+SvDwEgPIBlZqSnzi8rzNN0/4UJfEL7i6LUg=; b=PNk3L+xUksZq3iSsQ8Er9NxPj6JUz/Xu29S9GByrYOsrwBA8c5g+ipTZa6T1AgxxVn XRbyuQnGTDZz4U0mji+1ldYqWohOyR1HMs6hQlhz8mIfiIdsBbxb5JVHiKkL2RqNZ2pH WFJF+JrKqMj9oejh73ogf3wT6o1tcxc4U1bRE+MHT4ZeS6y3EU01/3KlB/TaL2bBlQZz 7lWNKeJhE/8mRBFH59Mz1LvUmjSzSjEzBtz07ZECcY29WO0SOpTF3YQfsD9+FfQ2Fp1P ue8iMN+eVJBQqM3+d3XqHYIJ2QmVv9WBc5IQ5Bhalnv+OyHwMhwIFDCKd/uYxAKBQ2i/ iN7g== X-Forwarded-Encrypted: i=1; AJvYcCVU7uDO5GNHcPHaYL8DFodd2JuAmcIy67OK/E3uglKhCQlHayTTt+pcWukP75zq/7WeZfLlI+08h2nkfAf3PEMw2485EbYRGw== X-Gm-Message-State: AOJu0YxYVW6rXHKp+4xUlqFkErnCRCYGc57zMwcveHsFNPYEM2TAxxv2 XxpQaAXcShQF/KLFFn5lkZmq7WbGwKx+hLpcCCRQhf1yBwICLTQLZUfcIGnoAF4qNvTyRp2PGUz 1pWJhQC3VZTD6E0bvwEeJYCxEGOhtff7qBHeqM9sk X-Google-Smtp-Source: AGHT+IHk8/kpAI+81bOIEBsfcZe7B5x4OVtNNqSD6ajXX/pOVTMu1KqfFYQXrQmlIgmWv/DCigOxUARNHpv4YDBmuDY= X-Received: by 2002:a25:ba42:0:b0:dcb:be59:25e1 with SMTP id z2-20020a25ba42000000b00dcbbe5925e1mr1818811ybj.30.1711709030130; Fri, 29 Mar 2024 03:43:50 -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 18:43:39 +0800 Message-ID: Subject: Re: [PHP-DEV] [RFC] Invoke __callStatic when non-static public methods are called statically To: =?UTF-8?Q?St=C3=A9phane_Hulard?= , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000b32f600614ca503f" From: daddyofsky@gmail.com (=?UTF-8?B?7ZWY64qY7JWE67aA7KeA?=) --000000000000b32f600614ca503f 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 5:43, S= t=C3=A9phane Hulard =EB=8B=98=EC=9D=B4 =EC=9E=91=EC= =84=B1: > Le vendredi 29 mars 2024 =C3=A0 03:39, =ED=95=98=EB=8A=98=EC=95=84=EB=B6= =80=EC=A7=80 a =C3=A9crit : > > > 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. > > > > > Best Regards. > > Daddyofsky > > Hello ! > > I took a look at your proposal and I think about important issues if we g= o > this way. > > A static method mustn't used the `$this` variable because it simply > doesn't exists in the static context. The examples you're adding in the R= FC > are fine but they always rely to a specific `__callStatic` implementation > that will use a new instance of the object to forward the call. > > There are multiple cases where it'll be complicated to use it this way. > Two of them I have in mind: > > - What if the object needs important parameters in its constructor that > aren't available in the static context ? Or those parameters need to be > initialized outside of the `__callStatic` method? > - What if the underlying non static method we are trying to invoke is > using the `$this` variable? > > In those two examples, I would prefer having a fatal error that explains > that I'm not doing the call correctly (calling a non static method in the > static context) to ensure it'll be easy to understand and fix. > > The use cases you are describing here have been fixed in the user space b= y > the Laravel team. It's a very specific way of working that's mostly > specific to Laravel. > > For sure it makes the code harder to read since you can't jump to a real > method easily (because most of the methods are magic ones and are forward= ed > to underlying objects). I don't tell it's wrong but I'm not sure it's > relevant to make the whole language simplify this process. > > If there is a way to work correctly with those static vs non static calls > and capture relevant errors to expose them to users, that's fine. > > However, I think this is an important behavior change because it'll allow > a new way to work with method that were forbidden before. > > Regards > St=C3=A9phane Hello. Thank you for your interest. In fact, `__callStatic` is often used for static-like singletons, and such examples are likely to be the majority. Regarding the two issues you pointed out, the first can be resolved by adding an initialization method like `init`. It's common to use a separate initialization function when dealing with general class operations, especially when there is a lot to initialize. The second issue is actually the same problem that exists today. Since `__callStatic` is called in the case of static calls to private or protected methods, the use of `$this` is not exclusive to public methods. In other words, the `$this` issue applies the same way it does now. Allowing public methods does not create a problem that didn't exist before. If it had been the case that calling non-static methods statically always resulted in an error, the issues you raised would have been significant. However, private and protected methods can already be called without error. Even if this RFC is not accepted, the points you mentioned still apply. Regards Daddyofsky --000000000000b32f600614ca503f 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 5:43, St=C3=A9phane Hulard <s.hulard@chstudio.fr>=EB=8B=98=EC=9D=B4 =EC= =9E=91=EC=84=B1:
Le vendredi 29 mars 2024 =C3=A0 03:39, =ED=95=98=EB=8A=98=EC=95=84=EB=B6= =80=EC=A7=80 <= daddyofsky@gmail.com> a =C3=A9crit=C2=A0:

> 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.
>

> Best Regards.
> Daddyofsky

Hello !

I took a look at your proposal and I think about important issues if we go = this way.

A static method mustn't used the `$this` variable because it simply doe= sn't exists in the static context. The examples you're adding in th= e RFC are fine but they always rely to a specific `__callStatic` implementa= tion that will use a new instance of the object to forward the call.

There are multiple cases where it'll be complicated to use it this way.= Two of them I have in mind:

- What if the object needs important parameters in its constructor that are= n't available in the static context ? Or those parameters need to be in= itialized outside of the `__callStatic` method?
- What if the underlying non static method we are trying to invoke is using= the `$this` variable?

In those two examples, I would prefer having a fatal error that explains th= at I'm not doing the call correctly (calling a non static method in the= static context) to ensure it'll be easy to understand and fix.

The use cases you are describing here have been fixed in the user space by = the Laravel team. It's a very specific way of working that's mostly= specific to Laravel.

For sure it makes the code harder to read since you can't jump to a rea= l method easily (because most of the methods are magic ones and are forward= ed to underlying objects). I don't tell it's wrong but I'm not = sure it's relevant to make the whole language simplify this process.
If there is a way to work correctly with those static vs non static calls a= nd capture relevant errors to expose them to users, that's fine.

However, I think this is an important behavior change because it'll all= ow a new way to work with method that were forbidden before.

Regards
St=C3=A9phane

Hello.

Than= k you for your interest.
In fact, `__callStatic` is often used fo= r static-like singletons, and such examples are likely to be the majority.<= br>
Regarding the two issues you pointed out, the first can be resolved = by adding an initialization method like `init`. It's common to use a se= parate initialization function when dealing with general class operations, = especially when there is a lot to initialize.

The second issue is ac= tually the same problem that exists today. Since `__callStatic` is called i= n the case of static calls to private or protected methods, the use of `$th= is` is not exclusive to public methods. In other words, the `$this` issue a= pplies the same way it does now. Allowing public methods does not create a = problem that didn't exist before.

If it had been the case that c= alling non-static methods statically always resulted in an error, the issue= s you raised would have been significant. However, private and protected me= thods can already be called without error. Even if this RFC is not accepted= , the points you mentioned still apply.
=C2=A0
Rega= rds
Daddyofsky
--000000000000b32f600614ca503f--