Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122820 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 721921A009C for ; Sat, 30 Mar 2024 10:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1711794544; bh=4TebI8PYX1Y8MXarTGXV1fuyYJw6r4VxDAm0V0KyWb4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=D6Ilnm/NvvQ2NxiJDcwpb3YJFaD3b9pzUciAGoI5XZd1IPhEVj9/KUbBx7VVZLsjq jS9gDNt4IlknNafZWNvasK0+4zsBA8Ag5Md1IXsdb/I5W8w/5nJnAku0uGVqHl5ZoS TS3m5t3wRE7gxItIMrMA7XmAInEWnSMqY8oiex6VnXMVbLToEs8zKZgfHRBrxUyZ9b 1hw0ayTwVkgcs6zjIcUoFx8Mo76r8h/NEtYBjsauPgtYrbV63pfyTb4V1kys8InNQU jh0RxRhdPYRgjvQie4TedXLKmbU/cYJ+I13BUyCSolTkOUy70NscSMyaykBCJj9DZW 0LnbWN6P6f6qQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B09EE180070 for ; Sat, 30 Mar 2024 10:29:03 +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-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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 ; Sat, 30 Mar 2024 10:29:03 +0000 (UTC) Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5a558d9c33aso1567998eaf.1 for ; Sat, 30 Mar 2024 03:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711794516; x=1712399316; 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=sCAkYbG6Dc5OybYiaqhphLV+wg5W1rBqflngcdFsR0Q=; b=FjfWkNb1be3lPLFjAGSTLycQ9onGY0kwR3f81pkI/f9eWEQ82rMjmxSymGzXatiXJ4 EUw8SpeJncC5bd3GxOXENQn2sIRmYk8EAozdn6gYdTovnoRnd1LNRpYar9/uMU27MgHa 0t3DrVo5YZ+nquUoEpvJGZXPSnetNkDEJ0GIqqaU41IuIyAEpwyohnVsESL/7foxAKXE s4oag5ocfM0BMBslvxU7O0khm+rCm9nRJxImYCwKFGKuOgXqVnEKurQW48sb+MfLXQnn C3B52v48J0JFQx5R327fXwx2gh6UzHkUQpKda8nigHT/r2/HJpOWVHFz6XY54Yss25iP RI0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711794516; x=1712399316; 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=sCAkYbG6Dc5OybYiaqhphLV+wg5W1rBqflngcdFsR0Q=; b=Iu5K5udC8oCj3gFqziET+5ggbad0j0dEkf4V7L1ocLA4ps2Cdl2OGhZuRpcGTalGyP FUTTLJ86aGDwqu0BDmWbrFvaIJxaND/uuAVt3CaQaii0CWRNQXJVNLI9E2d49Z65li2a lQ8xflQFiBrFO0In/n9szlGz5KJqKC4Woi6VknanPwy9NFlHMb1DT7c+A4g5Ltn6mvVF sSpdSZEynzEvJLCpEQ7K1ej4AX9jQp4Rq68jilCtt2mxzEdAfXngIAj0VzmPsXTSoJ44 pMMXQDUOUkywiNZr4L5iplesCPlieh6Zu7ZD6NPSYB/b8eHFpS2yaUxOjWro3Q4s/AUf SFrQ== X-Gm-Message-State: AOJu0YwpGaZpY9UIjyt6V+sBddN8xtahAj8/KLH5we8FHumjxrrJUCLK ThwajjtIosMqwbPZHFYrvICeB5vn7w++h5W5PMXTGnEs8yRiUdibj4IsbIDEmLk9hl2yPzSmLhW 1yC5D3JLJ8x6BjzWyFqoK6hkStng= X-Google-Smtp-Source: AGHT+IFkq++NFjYS3BJqOvx0wKIsRB1zIxm+5MH00nCgGsguXLdOgnc4Ihtlp/Nn+g7q3ueK01B0j0kHHWsZAHtPXIM= X-Received: by 2002:a05:6820:3082:b0:5a4:97f0:ca44 with SMTP id eu2-20020a056820308200b005a497f0ca44mr4343151oob.5.1711794516124; Sat, 30 Mar 2024 03:28:36 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 30 Mar 2024 11:28:24 +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 Sat, Mar 30, 2024 at 1:06=E2=80=AFAM =ED=95=98=EB=8A=98=EC=95=84=EB=B6= =80=EC=A7=80 wrote: > > > > 2024=EB=85=84 3=EC=9B=94 30=EC=9D=BC (=ED=86=A0) =EC=98=A4=EC=A0=84 2:15,= Robert Landers =EB=8B=98=EC=9D=B4 =EC=9E=91=EC= =84=B1: >> >> 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 f= eature cannot be used. >> >> This sounds like a bug or feature request with your IDE, not a problem w= ith PHP. >> >> > This code is very clear, aside from the fact that the method is not st= atic. >> >> 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 featur= e also 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 si= ngle 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 na= vigation 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= statically, 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 > > > Hello. > > I'm not very familiar with documentation. It would be helpful if you coul= d suggest how to fix the problematic parts. > > Using the example of the IDE meant to illustrate that it should be intuit= ive enough for the IDE to find it directly. > > Even currently, `__callStatic` is called in cases of non-static methods t= hat are not public methods. `__callStatic` already acts as a rule-breaker. = It seems like there's a desire for the magic method to be named as such wit= hout actually causing much magic. The current `__callStatic` is like a magi= cian who can use high-level magic to hit targets behind doors or invisible = targets but can't use basic magic to hit a visible door. > > While it's good that the PHP kindly notifies errors, I think it would als= o be beneficial to provide users with options to do other things, specifica= lly when they intentionally use `__callStatic`. That's the core point of th= is proposal. > > If there are better examples or ways to explain, I would appreciate learn= ing about them. > > Daddyofsky My main issue with the RFC comes down to the fact that it suggests that this is valid: // https://3v4l.org/0ufkt class Test { public function test() {} public static function test() {} } Having two functions with the same name, one static and one non-static is (currently) an error. Allowing callStatic to break this rule without being able to write the above code, feels inconsistent. While PHP is full of inconsistencies, adding more of them isn't the right way. I'd much rather see static and non-static methods being able to have the same name -- in which case it would make sense for callStatic to work as described in the RFC. Robert Landers Software Engineer Utrecht NL