Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122810 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 40DD51A009C for ; Fri, 29 Mar 2024 18:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1711736137; bh=JpMekhz6w2MbH+9YSgS/z8AYLjgeneVvkOQq+yb8wGc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Z/JF6cHI2MHoqILeK9M6+wV9EOu5d4vWsD0NfotwoYSk+3Z2iAjoSIC/hGnqOJutG pEU7qM2g/op6Or8QZ11lC1PdEw3yzUimCd/jK6423hTU6JGVsZgsmAz1UKZb3bfT2O bg2RhPSqzVN7vuazAjISOeMh9nZUgsi1VYwCFo+UoSiewfP/TNgqtIuKfGiVlyZpW3 Fuzj3e/aJ4h6rTp5DrSYAfPzgDePTF9mQU+Z6D3do/MwL5FMyi//oEbjLqfw3X4gFn izyC0mYbOHnZ4mKCjddk7xhtn7VPfVlWE7Kz7xSzQ+jY3x3M2aaX52k16vBxn6uwzB fUtRCbko4wgaw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F071F1801DA for ; Fri, 29 Mar 2024 18:15:35 +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,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (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 18:15:35 +0000 (UTC) Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5a4a102145fso1101160eaf.3 for ; Fri, 29 Mar 2024 11:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711736108; x=1712340908; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZP4gpfv9j3OaUwjhg7jw9AFAEB28l2ZyFIc2eWmka2A=; b=WbYz4qYRQDDtd6fn4SqgT+GBr6/wJKpWkme8kgo/AIL5BtIF7oLORtgfDVK3jlLRqx dhTwllOAf9NR93nPgO1dbOSKcCK32Vpf8P8UG8OHU58xX/8IicuFrx15SO81QLWp3P5g TbEiAqq5SL+H/5WAvrrPcb4LbVwUvepW6Ap2JiiTdAnpvPnE9BVOS+sBRRSw3eLzUn2L 9G2BwjhOARyuDAJ6DZ6J0JsL9RTa9P3q0D77ptCq/3yUeC82aGIRjnVaa6W0Hhv/6odc GPRfKY5uzwbqYphlfImICTft0jOdliJ1BU37p34utVgN3qICK2p+M1EcUQ6NHdgSp4QD W7Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711736108; x=1712340908; h=content-transfer-encoding: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=ZP4gpfv9j3OaUwjhg7jw9AFAEB28l2ZyFIc2eWmka2A=; b=O0GxxV1Sv7ACf3zphHd81fHu2rL6QcDBhMwPuQj7dHnA9BkJc3ONDcH2knGQHIYbl+ Jq1Ii3TXPJbq+ZRDsyBDE533EBwWhZ6gQbz6+pBJehISxwkZNRkuDFJrGlRLFN6cbhOc 2hM2OwhG0H7mU/6GbJKwbbTPvsQ1cFBl2nGMK1EfybX3c/PemKTmEjjtcSFYyswcp/ug Q1uDjmmREt7CMLjM/ayDdJEoE7vvpO2AmTX5E/Xzjlh2CtcB5S/CK/N9MygAakaTDksz J5NgAu9R0hYR8QpibMrKzVoeTCBKDLsANAat1BCM+Am+5if8FhmqFRBT8LgJ32cFjP41 fTTw== X-Gm-Message-State: AOJu0YwJ9lTFbMPyenwf89Qr+09BahV+OUCpHynUoANTh15ZDj6kLgQl YuuThUbeAw5wXPknyTQKuk6poXT5ydrvEtLsoldilsK1ijT7WHN5PrBz8jm1+/DQfLrIb3iZPOx x+pn4qtV6+3HoV/xv1kPBqOpw6rawqNDKZAZ80g== X-Google-Smtp-Source: AGHT+IFaF85fb1jgjtebHDgMFiKik6TFJe6wNH7HrH1Yl9C1uuGgkq3aVVGa68AmEzeahTB7QnFP98jyBK3X/XfzzL0= X-Received: by 2002:a4a:dc98:0:b0:5a4:ae86:118f with SMTP id g24-20020a4adc98000000b005a4ae86118fmr2207544oou.8.1711736108614; Fri, 29 Mar 2024 11:15:08 -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 19:14:54 +0100 Message-ID: Subject: Re: [PHP-DEV] [RFC] Invoke __callStatic when non-static public methods are called statically To: =?UTF-8?B?7ZWY64qY7JWE67aA7KeA?= Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Fri, Mar 29, 2024 at 3:41=E2=80=AFAM =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. > > Best Regards. > Daddyofsky Hey there, Some general feedback: The RFC is a bit hard for me to follow, for example: > However, the IDE cannot find active method, and the Go to Definition feat= ure cannot be used. This sounds like a bug or feature request with your IDE, not a problem with= PHP. > This code is very clear, aside from the fact that the method is not stati= c. Clear to whom? As a developer this looks downright confusing. I can't even guess what the actual behavior is. If you call a non-static method statically, its currently an error. Why would this not be an error? > The IDE recognizes active methods well and the Go to definition feature a= lso works properly. What is stopping the IDE to taking you to the __callStatic method? That would be the correct behavior IMHO, not the implementation for instance methods. > Even if there are only a few core methods, it cannot be made into a singl= e file. There is nothing stopping you from putting multiple classes in a file. > As can be seen in the above examples, the code becomes clearer, and navig= ation through the IDE works much better. I completely disagree. It mixes concerns and makes spaghetti code into incomprehensible code. Also, maybe you should take up IDE navigation with your IDE? > Instead of throwing an error when a non-static public method is called st= atically, the _ _callStatic method should be invoked. I completely agree with this, btw. Your examples could use some work and shows all the reasons why it shouldn't call __callStatic(). A real life example, that has nothing to do with a specific framework: When generating proxies for existing types, you often need to share some state between the proxies. To do that, you put static methods/properties on the proxy class and hope to the PHP Gods that nobody will ever accidentally name something in their concrete class with the name you chose for things. To help with that, you create some kind of insane prefix. If __callStatic() were called ALWAYS in a static context, even if a non-static method exists, then collisions would literally be impossible. But at that point, why can't I just write: class Test { public static function test(): string { return "hello world"; } public function test(): int { return random_int(); } } ??? I feel like this is your real RFC and should be allowed if we're allowed to __callStatic() to instance methods. I don't think it makes sense to have one without the other, and then what you want with __callStatic() comes naturally, instead of this weird and confusing RFC. Robert Landers Software Engineer Utrecht NL