Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119810 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55213 invoked from network); 31 Mar 2023 13:12:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Mar 2023 13:12:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BAB2A180538 for ; Fri, 31 Mar 2023 06:12:35 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 31 Mar 2023 06:12:34 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 117393200902 for ; Fri, 31 Mar 2023 09:12:32 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Fri, 31 Mar 2023 09:12:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1680268352; x= 1680354752; bh=UgZlRtyQJwtEoSOfMFx4FuAJZCnUhdLisWY6se3+39g=; b=l ntl7GpItCexc76kdw7ETFlHCBN8wzWPtLQJWOThFCIUeb8/MGaUonztvBFeK4mZ/ BW/wIOb5XVooL9NLOswDet5hgHyXxQfgRs5MDqM5rf0dmjgqytaDQnbL4q8JIuht 2b7zPm5PeMoHLie+v2zxzIBnJWPdTw64Yph3GiwAsZIMrvIUE6Qaea8oYpceLD6+ PBZcBJUXcT5reFyMp90VzBwbUNPniv7VHbD+UHhpCZFmHHtWrJhUXH8TjwUTGJU6 4a9PpVtOpQziwYpFSP5DR8talTQOUHqbuX8PeCZ67tNCogo1AyOjKOXLYEDFxl8M n5VbmeBuyeAcb//EXBWwQ== 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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1680268352; x=1680354752; bh=UgZlRtyQJwtEo SOfMFx4FuAJZCnUhdLisWY6se3+39g=; b=UnN578M9CX3Z1VlElZAy4Uut87Waz mQh36W95bS0zLpjIcxgmSo/3q0HKa1bFZzZ33sVOwlSoqJawWEVyGgnRwEtHZUhY 603405pGnMuqS292s1NLNSKx6V3oJXol4ndSaxKDQWjifU1SAWE0hbGIG/vCesYI XNgwBOMAG6rws5kvtntegH0k/GZx5QSfksgng1T714yTPgk8tO04HPIZ6Sg9gjuI kMjGhGu2903UnKP+xYgqW8APqi6wOXgL4WB6i4A+5/GF7DVt/kNWWv/2bXW9gdWt X1Mc2Gh4MYu0SQwrx9VfHhJWkz5rW1TakzlbLYDJT+xumPIyxkeb46rrQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeiuddgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne goufhushhpvggtthffohhmrghinhculdegledmnecujfgurhepofgfggfkjghffffhvffu tgesthdtredtreertdenucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolh grrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpedu feejhfehjedvgefggeekheeuffevkedvkeeujeefffeitdfgieehjeejheehleenucffoh hmrghinhepghhithhhuhgsrdgtohhmpdefvheglhdrohhrghdpphhhphdrnhgvthenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihse hgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 6057D17000A0; Fri, 31 Mar 2023 09:12:32 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-238-g746678b8b6-fm-20230329.001-g746678b8 Mime-Version: 1.0 Message-ID: <19279c3e-b74c-4a7c-9f0b-d456c9259406@app.fastmail.com> In-Reply-To: References: Date: Fri, 31 Mar 2023 13:12:11 +0000 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Traits and redeclaring static properties From: larry@garfieldtech.com ("Larry Garfield") On Fri, Mar 31, 2023, at 1:07 PM, Ilija Tovilo wrote: > Hi everyone > > A few days ago we received a bug report about an inconsistency with > traits and static properties. > > https://github.com/php/php-src/issues/10935 > > https://3v4l.org/Dll1m > ``` > class A { > static $test; > } > class B extends A { > static $test; > } > A::$test = 'A'; > B::$test = 'B'; > var_dump(A::$test, B::$test); > // string(1) "A" > // string(1) "B" > ``` > > https://3v4l.org/SClLn > ``` > trait Foo { > static $test; > } > class A { > use Foo; > } > class B extends A { > use Foo; > } > A::$test = 'A'; > B::$test = 'B'; > var_dump(A::$test, B::$test); > // string(1) "B" > // string(1) "B" > ``` > > To summarize, a trait does *not* add a property to a class that has > already inherited the same property from its parent. This makes sense > for non-static properties, as redeclaring the property essentially has > no effect. For static properties, however, there's a semantic > difference in that redeclaring a static property creates a new slot in > the current class that is separate from the parent's static property > slot. > > This was never explicitly specified by the traits RFC. However, this > sentence hints at the fact that the two examples above should behave > equivalently. > > https://wiki.php.net/rfc/horizontalreuse >> It is almost like a language supported and failsafe copy'n'paste mechanism to build classes. > > I created a PR to align the behavior of the two examples. It targets > the master branch to avoid any potential backwards incompatibility in > a patch. > https://github.com/php/php-src/pull/10937 > > Please let me know if there are any concerns about this change. > > Ilija This seems reasonable to me. "Compile time copy and paste" is the mental model we've been training people to have for a decade, so ensuring it actually works that way in corner cases seems like the right move. I don't think I've ever seen code that would have a behavior change as a result. --Larry Garfield