Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119809 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53778 invoked from network); 31 Mar 2023 13:08:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Mar 2023 13:08:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2376B18037E for ; Fri, 31 Mar 2023 06:08:04 -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=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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:08:03 -0700 (PDT) Received: by mail-pj1-f47.google.com with SMTP id p13-20020a17090a284d00b0023d2e945aebso8653718pjf.0 for ; Fri, 31 Mar 2023 06:08:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680268082; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=p3iD09F2SF5xmT79WJ+IIHd5dqOZRApX+oucsULzKhI=; b=Cwx9m3ikMuwcCKI5hfLnc0gNs1d2OAK95/NkE0GLTjGDZDwSlH5mYyZhEVHPXqrgOt vMOKAVRuA7P20G3UEwpAAj9/+h9I+9c4MWXNpFhqo+5XRXNo2z9SVn/GcwpxEXeJ5iPv wiQvmF9kWLQ16OZ55DDGPfB1DjJ+B55+9RbajxdklRCq8niw0ULCMZ5tapuEY696qLgH A6wjPyrD5XCaCdQmC3dXUX71H35ZWqMKR2KIpkmyzmXOqPDtJfFnlx2Bs62/48CIac9U UjsPZR00KeGzbqCgAKc4WcspEUs1RROHDuA82jeM02XyLyCDWNTwTF/nKhtlqMkjp7JR ZOCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680268082; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=p3iD09F2SF5xmT79WJ+IIHd5dqOZRApX+oucsULzKhI=; b=YvKWuzfKJYq3d1rVkLutpPFJbRG/h0M0T0cN4r5YVslVvkSI8oITa46wG3QTgplPqF uL8AFjSYvOuWTvYxpJi8R0m3qa+vyTsTn8IVrMKaLUjcQMcg3072nbgWrlNqize2YjkF EFxO6nKFJuPZ2n3DteaG4rqjpyPKv418HHYxTjGqbCSXiTbeJaH8VqJmMQbZ+SV0yi68 Am/EWstNdhngVGcutUAWqiaWQQkfqrhAzDISgHkeyw0KNWPaEP1rPV4m8+XcFBnnJPAJ 5p1oErBa4/0LLy24OLn6D1uB8zm9obtbleKp8iyTyqlz9eluNw63q/GjFpzJleXPEgkX I9pA== X-Gm-Message-State: AAQBX9evWH/NdwIdg5MzhtiBLLjSxFoyrinKCCitkVr+2aHTfnJtefKG TmLR05VmLlchs74mV8Eajz+mBGl5qACXWk//Mk+5jYRSGgU= X-Google-Smtp-Source: AKy350ajlT0BT/+r7ttc0DgtY4fWnT7yt1FFqICCJ7U4T/smWeRff52nnLy6Q448KrQpX8wWeitcpgDgzT6LHxG/4b8= X-Received: by 2002:a17:90a:d318:b0:23f:6c5:8af2 with SMTP id p24-20020a17090ad31800b0023f06c58af2mr8312869pju.2.1680268082132; Fri, 31 Mar 2023 06:08:02 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 31 Mar 2023 15:07:51 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Traits and redeclaring static properties From: tovilo.ilija@gmail.com (Ilija Tovilo) 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