Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122784 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 43A121A009C for ; Thu, 28 Mar 2024 09:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1711618856; bh=V4C0ALcKff9P+N1UftlvnuP1PXyASDToB3ZZhs2FGxQ=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=WUFp+0V2wyGM7EoRfzu+ExrmAGBHm6/EAExJJz/XjFaRnuai7qyIjdThsZeoCgqPV EseYWlj/aZBoIPuuFuOkd1tBHnJ/FKArZ5VlEBPverlKhuxYWUcILDB1lGfMKAJD0s ylDYaqrE7Hp9qrNf3/d0PjES4uDr4A/ezIQbx84J0RwJfDDNc0LnGaSmDsgfb5wUio Go4LOnSx+5Q+aXDqyJJhO4MjLeROTtAiHxUJmKIDcRu1dW8Joc0wnYjktsbUaFt+qm PXPi9DdiNGFlMjQrBnWIdsBSzfmw0SYCK5cy9OaJsdj9nd9it1SR382vNuoy1qKn2I vURsUfoKSXngQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A61F018006C for ; Thu, 28 Mar 2024 09:40:53 +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-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 ; Thu, 28 Mar 2024 09:40:53 +0000 (UTC) Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-56be32b9775so813806a12.1 for ; Thu, 28 Mar 2024 02:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711618827; x=1712223627; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=D0npN7Vlz6o+2rIMgF+qGhYapDYCgI90fThGJMChbIk=; b=XnT+BGnhu3x+Ifpqn60AltT7P3ESIu+6yIeu2QmhBNjiTE1ULYyW8847u6jyx5dLvz yVtQSE2zVjajBHonaiwUEc9DVyFK6cpaXl+1c4cXo1bbaNJIjRoX1EQ0KgKs0eE2rn/W KEGAWSJt24sLToTrQgyvOwepa6D15HHFjT7bz1lm/OXTubf2DyCWDhi1l3BrWr+G81GD 8hMb3O6oqkES/J+9fQwq0/KympJIa3vGFupb2Q5DBQVTrY5EKHuCCvcbqKZ/QHmM/98w lp/VOXY3gbNWcCJOzWmx/UaH56BLt1g58vVffmj1YPcXO23NIUc46bFJoASoQFipx1Al ansg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711618827; x=1712223627; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D0npN7Vlz6o+2rIMgF+qGhYapDYCgI90fThGJMChbIk=; b=nKQYMS/dc6FN2qzexQYdoQUYYEr2YElUvRwfWKKqg022EjMQERrr2oYH5uwWW5BHyU QTWPKb8x+4nNQtVS2n2CsjHUBugXjIt7MAXpCDMd3sJa/m+g57IvM/e+hZ34dyiIr/uw WsLM59Usjd06Rsl+3PNjpy/MrLiCiU3Uw0CkvxjQiZioJVPTbhjc8GSdogBpc4XIa8+O ztxzUeiLFW4aaBzqAUHhHvwNjr88Bk8RgNsW6th64K1i2atOoeBykDbkEI8jQm3vvEJY w8gqoztAFO983Tk7RxnPz9eWYkYsqZgf3MpKcOKDHqpSh5j32AW8ALYWp2B5Mk/GKvsR b4Zg== X-Gm-Message-State: AOJu0YwUhxjlnk+b/OIKp5VgvWaIcdgK5WoC6G3M1qKHZFXldfYobP1O A8k0TGU9gGnMD80AYFnpc6Fr3KonV9oIp0PeoYGsbWLg2Zy7pjnw X-Google-Smtp-Source: AGHT+IH1M3orfwGQTzJAu67cMcq8V+YW0wXzQXRKicEicqQ1XMnJijlfJiMBX+XFfIvSrMXnLCK/iQ== X-Received: by 2002:a17:906:ad2:b0:a4e:f82:375e with SMTP id z18-20020a1709060ad200b00a4e0f82375emr1306328ejf.73.1711618826275; Thu, 28 Mar 2024 02:40:26 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id w4-20020a1709062f8400b00a4e07f8b6bfsm534930eji.59.2024.03.28.02.40.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2024 02:40:25 -0700 (PDT) Message-ID: <3ECDC57B-9D22-4A0C-8E02-5720C90EF3BA@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_83546924-0DDD-49E5-910A-83663045C684" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.400.31\)) Subject: Re: [PHP-DEV] [RFC idea introduce] The issue where the __callStatic magic method is not called when statically calling a public method. Date: Thu, 28 Mar 2024 10:40:14 +0100 In-Reply-To: Cc: internals@lists.php.net To: =?utf-8?B?7ZWY64qY7JWE67aA7KeA?= References: X-Mailer: Apple Mail (2.3774.400.31) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_83546924-0DDD-49E5-910A-83663045C684 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 28 mars 2024 =C3=A0 03:29, =ED=95=98=EB=8A=98=EC=95=84=EB=B6=80=EC=A7= =80 a =C3=A9crit : >=20 > Hi. >=20 > I would like to register an RFC on the following issue. > https://github.com/php/php-src/issues/13813 >=20 > To summarize briefly, users expect that the `__callStatic` magic = method will be called in all cases when a method is not static while = using the `__callStatic`. However, in reality, if the method is public, = the `__callStatic` magic method is not called, and an error still = occurs. >=20 > I would like to hear your opinions. > I also hope someone can help with the RFC registration. >=20 >=20 > -------------------------------------------------------- >=20 > ```php > class MyClass > { > public static function __callStatic($method, $args) > { > echo $method . "\n"; > } >=20 > private function privateMethod() {} > protected function protectedMethod() {} > public function publicMethod() {} > } >=20 > MyClass::privateMethod(); > MyClass::protectedMethod(); > MyClass::publicMethod(); > ``` >=20 > Resulted in this output: > ``` > privateMethod > protectedMethod > Fatal error: Uncaught Error: Non-static method MyClass::publicMethod() = cannot be called statically in ... > ``` >=20 > But I expected this output instead: > ``` > privateMethod > protectedMethod > publicMethod > ``` >=20 >=20 >=20 Hi, One of the issue is that it is not possible to determine statically that = a certain call is static or not. It is possible to determine it at = runtime; but you must be careful to articulate clearly the rules. = Although it is absolutely possible to have logical rules, I fear that = they couldn=E2=80=99t be sufficiently simple in order to avoid = confusion. In the following real-world (but hopefully rare) case (it is taken from = my own codebase), I am calling a method of a grandparent class. It is = *not* a static method: ```php foo =3D new class(/* ... */) extends Bar { // ... function Header() { $grandparent_class =3D get_parent_class(parent::class); $grandparent_class::Header(); // ... rest of code } // ... }; ``` In the following more general case, I might intend to call to a static = method. However, as of today, a call to a non-static method will occur = if `A` has a non-static accessible method `qux()` *and* `$this` is an = instance of `A`: ```php class Foo { function baz() { A::qux(); } } ``` (In older versions of PHP, a non-static call would occur even when = `$this` is not an instance of `A`. Hopefully, this is no longer the case = since PHP 8.) =E2=80=94Claude= --Apple-Mail=_83546924-0DDD-49E5-910A-83663045C684 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
Le 28 mars = 2024 =C3=A0 03:29, =ED=95=98=EB=8A=98=EC=95=84=EB=B6=80=EC=A7=80 = <daddyofsky@gmail.com> a =C3=A9crit :

Hi.

I would like to = register an RFC on the following issue.
https://github.com/ph= p/php-src/issues/13813

To summarize briefly, users expect = that the `__callStatic` magic method will be called in all cases when a = method is not static while using the `__callStatic`. However, in = reality, if the method is public, the `__callStatic` magic method is not = called, and an error still occurs.

I would like to hear your = opinions.
I also hope someone can help with the RFC = registration.


--------------------------------------------------= ------

```php
<?php
class MyClass
{
public = static function __callStatic($method, $args)
{
= echo $method . "\n";
}

private function = privateMethod() {}
protected function protectedMethod() {}
= public function publicMethod() = {}
}

MyClass::privateMethod();
MyClass::protectedMethod();MyClass::publicMethod();
```

Resulted in this = output:
```
privateMethod
protectedMethod
Fatal error: = Uncaught Error: Non-static method MyClass::publicMethod() cannot be = called statically in ...
```

But I expected this output = instead:
```
privateMethod
protectedMethod
publicMethod
```=



Hi,

One of = the issue is that it is not possible to determine statically that a = certain call is static or not. It is possible to determine it at = runtime; but you must be careful to articulate clearly the rules. = Although it is absolutely possible to have logical rules, I fear that = they couldn=E2=80=99t be sufficiently simple in order to avoid = confusion.

In the following real-world (but = hopefully rare) case (it is taken from my own codebase), I am calling a = method of a grandparent class. It is *not* a static = method:

```php

foo =3D = new class(/* ... */) extends Bar {

  =   // ...

    function Header() = {
        $grandparent_class =3D = get_parent_class(parent::class);
        = $grandparent_class::Header();
       // = ... rest of code
    = }

   // = ...
};
```

In the following = more general case, I might intend to call to a static method. However, = as of today, a call to a non-static method will occur if  `A` has a = non-static accessible method `qux()` *and* `$this` is an instance of = `A`:

```php
class Foo = {
    function baz() {
    =     A::qux();
    = }
}
```

(In older versions = of PHP, a non-static call would occur even when `$this` is not an = instance of `A`. Hopefully, this is no longer the case since PHP = 8.)


=E2=80=94Claude
= --Apple-Mail=_83546924-0DDD-49E5-910A-83663045C684--