Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:122844
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 995D11A009C
for ; Mon, 1 Apr 2024 14:09:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
t=1711980576; bh=8f7IbE6hjNKQZDoHLLAPchlf/NDa+wyCdgt+oV8HYz8=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=mfvQZcXR3AiE4lS2tBBRII8kDBQis+aJC7cT/ve4qLhGNuzJIxfnZ1jq9mK1Cp9qS
CithqdFgwsVgQZD+YygqKfXtYQtMiTCoXUA33r7lt4edKSmFaLIwBzgAnB9S1EMjbi
olrq1iTRY2X57967qxaTd+2LcweLKv+bq8bFjEJwz1KbWgOMFallTafYSvDiY3OiKs
Q/lbf0NomXM7GI3gg9m9SQmXJ65DFkhuGBxMzxSOEorLeluvfPFavrw8wRww4AH6HH
GVNxOM9sAWs3jo3jYSrf0iHcTUpFHPTs8KQKDCihiJfcwRG2Jvy5aVNS3kDQ9k7bNm
Je6uxtvixwCow==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
by php-smtp4.php.net (Postfix) with ESMTP id 0A7FC180668
for ; Mon, 1 Apr 2024 14:09:36 +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=-0.9 required=5.0 tests=BAYES_20,DKIM_SIGNED,
DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE,
RCVD_IN_DNSWL_LOW,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 fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147])
(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 ; Mon, 1 Apr 2024 14:09:35 +0000 (UTC)
Received: from compute7.internal (compute7.nyi.internal [10.202.2.48])
by mailfout.nyi.internal (Postfix) with ESMTP id 7137513800F8
for ; Mon, 1 Apr 2024 10:09:07 -0400 (EDT)
Received: from mailfrontend2 ([10.202.2.163])
by compute7.internal (MEProxy); Mon, 01 Apr 2024 10:09:07 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc
:content-type:content-type:date:date:from:from:in-reply-to
:in-reply-to:message-id:mime-version:references:reply-to:subject
:subject:to:to; s=fm2; t=1711980547; x=1712066947; bh=vgCRLxlMY/
2c83uEZl+4vzAIax05EBDuUPdjfOd9Ric=; b=WOT61gq/Np/TbpKa3XnDV97M4y
K9gVWQV9il4uDb6y2RKDJldSbdnG5cAKrsl9U/cIHJyCFWSIRnnTbLOn6O5MekWz
SPFpORwuRwVgFfisgr39ylchH/n1lE8Sh3MXqD6pFEd5i89qZIiCIKQKFW0bPWrV
yH9KcZXIlrLyQIVJBT8+ioW8CfCnZ+Gx0ou9hLmVYKScJoUQz7FZN5Gbut2CwBkc
udn2L9VcNKOt+hp7RZ1ozeiJC8euzJhsz1gGe0bZdHHlLTo90UNmZ2HjNoS4ftFD
cAk6zZGXJ4a2AC6jDGZ44ipBCWI3FI3TPu26jnAB8qoQMStQZ/bVpklqZ3/g==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-type:content-type:date:date
:feedback-id:feedback-id:from:from:in-reply-to:in-reply-to
:message-id:mime-version:references:reply-to:subject:subject:to
:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=
fm2; t=1711980547; x=1712066947; bh=vgCRLxlMY/2c83uEZl+4vzAIax05
EBDuUPdjfOd9Ric=; b=TICCC5R2G17rhIL09L8cHGYvWUOV1tKON6gfpmYR8bxR
hi3MTEypup0A7K4klf4JvKo9y8zcZG3nTtqBLLLrZpPSVT9XTHHHrnmy+n+acfZo
LAeE64vs56d0dhmoqmwcFQwzJhq0Y68AaabyacgVrzRNo0E1PBTiPQeRh1x+B5rm
qFu2yDkQglubSPMd3mZHe8CN4XIIwwjLTiYyN97I0VfdmhWFUg4itIpJXrQPf+wY
/mG15H12fUqhSHrA3bMOvJ+tzm+MwbMRJkDCToV1svw93cYonE1+yA1i+DLS1cC/
6g28X+aQDuwUTyE9dybc9LD7r6OfANMrgAWI0v+rEQ==
X-ME-Sender:
X-ME-Received:
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeftddgjeefucetufdoteggodetrfdotf
fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
uceurghilhhouhhtmecufedttdenucgoufhushhpvggtthffohhmrghinhculdegledmne
cujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpedftfhofigr
nhcuvfhomhhmihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrd
gtohdruhhkqeenucggtffrrghtthgvrhhnpeeftedtkefhudekueefveegudevjeeiiefg
tdffjeehudetkeevheejkeeiueffgeenucffohhmrghinhepfehvgehlrdhorhhgnecuve
hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdr
phhhphesrhifvggtrdgtohdruhhk
X-ME-Proxy:
Feedback-ID: id5114917:Fastmail
Received: by mail.messagingengine.com (Postfix) with ESMTPA for
; Mon, 1 Apr 2024 10:09:06 -0400 (EDT)
Content-Type: multipart/alternative;
boundary="------------dW27XVHo0xP9ZWmcMHXlhhAe"
Message-ID:
Date: Mon, 1 Apr 2024 15:09:05 +0100
Precedence: bulk
list-help:
list-post:
List-Id: internals.lists.php.net
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: [PHP-DEV] [RFC] Invoke __callStatic when non-static public
methods are called statically
To: internals@lists.php.net
References:
Content-Language: en-GB
In-Reply-To:
From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]")
This is a multi-part message in MIME format.
--------------dW27XVHo0xP9ZWmcMHXlhhAe
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
On 29/03/2024 18:14, Robert Landers wrote:
> 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.
Separating static and non-static methods wouldn't solve this - the
concrete class could equally add a static method with the same name but
a different signature, and your generated proxy would fail to compile.
In fact, exactly the same thing happens with instance methods in testing
libraries: test doubles have a mixture of methods for configuring mock /
spy behaviour, and methods mimicking or forwarding calls to the real
interface / class. Those names could collide, and require awkward
workarounds.
In a statically typed language, a concrete class can have two methods
with the same name, but different static types, e.g. when explicitly
implementing interfaces. In a "duck typing" system like PHP's, that's
much trickier, because a call to $foo->bar() doesn't have a natural way
to choose which "bar" is meant.
> I'd much rather see static and non-static methods being able to
> have the same name
Allowing this would lead to ambiguous calls, because as others have
pointed out, :: doesn't always denote a static call. Consider this code:
class Test {
public function test() { echo 'instance test'; }
public static function test() { echo 'static test'; }
}
class Test2 extends Test {
public function runTest() { parent::test(); }
}
(new Test2)->runTest();
Currently, this can call either of the test() methods if you comment the
other out: https://3v4l.org/5HlPE https://3v4l.org/LBALm
If both are defined, which should it call? And if you wanted the other,
how would you specify that? We would need some new syntax to remove the
ambiguity.
Regards,
--
Rowan Tommins
[IMSoP]
--------------dW27XVHo0xP9ZWmcMHXlhhAe
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
On 29/03/2024 18:14, Robert Landers
wrote:
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.
Separating static and non-static methods wouldn't solve this -
the concrete class could equally add a static method with the same
name but a different signature, and your generated proxy would
fail to compile.
In fact, exactly the same thing happens with instance methods in
testing libraries: test doubles have a mixture of methods for
configuring mock / spy behaviour, and methods mimicking or
forwarding calls to the real interface / class. Those names could
collide, and require awkward workarounds.
In a statically typed language, a concrete class can have two
methods with the same name, but different static types, e.g. when
explicitly implementing interfaces. In a "duck typing" system like
PHP's, that's much trickier, because a call to $foo->bar()
doesn't have a natural way to choose which "bar" is meant.
I'd much rather see static and non-static methods being able to
have the same name
Allowing this would lead to ambiguous calls, because as others
have pointed out, :: doesn't always denote a static call. Consider
this code:
class Test {
public function test() { echo 'instance test'; }
public static function test() { echo 'static test'; }
}
class Test2 extends Test {
public function runTest() { parent::test(); }
}
(new Test2)->runTest();
Currently, this can call either of the test() methods if you
comment the other out: https://3v4l.org/5HlPE
https://3v4l.org/LBALm
If both are defined, which should it call? And if you wanted the
other, how would you specify that? We would need some new syntax
to remove the ambiguity.
Regards,
--
Rowan Tommins
[IMSoP]
--------------dW27XVHo0xP9ZWmcMHXlhhAe--