Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113272 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55250 invoked from network); 25 Feb 2021 21:47:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Feb 2021 21:47:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DD1E31804E4 for ; Thu, 25 Feb 2021 13:36:42 -0800 (PST) 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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 25 Feb 2021 13:36:41 -0800 (PST) Received: by mail-wr1-f54.google.com with SMTP id e10so6436281wro.12 for ; Thu, 25 Feb 2021 13:36:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6XaWca06FFjEQkNaTdwMO+p8z867H3Af7E6FCuqFo1w=; b=IqkXO+3rJ3T5z/SbYPSdHJMgIKzftb6DDi6j0ZPhiYavFZLNH0x5AN6w+PvtKT2FaS IF65FjS+VgbCRxmtGX+9B9QMR0qQ4WnTSnKLI6z2u5/j8pvs/TihJ4eNTnGY0YuiGqtT LEdw0WxKOSvfqdRRf5W+0lvU+DRiHKl1KeSMC3dwVUnJkmZO6P7RxpqfiQYNlqjJ0DuZ eIjofI5vMc3bDRIkKWUGdcUJ1rfYuZIhaePYpZ0o9AnmEnr7v4YlGfSjKOHXueH4/wnd 36KN4wCw5LBol3yl8+mVm9kUlejPMCmbQYySl2XWugSTir0BiJiHspBZ0pgt7IYPGS7s qVWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6XaWca06FFjEQkNaTdwMO+p8z867H3Af7E6FCuqFo1w=; b=Wq5aezeyoVkfCL+c3rxw62OzxmI75qGdpBA0W1Tky2SiQUx4qnmpn540INrg26AAT7 TG6gvA8i3tlQutv1QonTFwTBaWLGfDt0YvOU/91aREQkxWBh+2xxj8ObLNy049UOrmuM /FLB3rsI0eXK6XoQaPtRxslv6HttrQ6AKFbHI+K4j5m7tKn53Vpw5/KjXGxwcmjwQIyP laCkCU73+H02UAzOZjY0zLM7tbIH2zeXyS/Qn2+9gWe3PuMNwfagaSF2YVZA2rMdkvzG SA9SnhyAsFwA3b7qTis2crteCM+8mbMGhPc7GavGpt45n7MdXuHmqjHUHESWO1GauEJP x7IA== X-Gm-Message-State: AOAM530LZjZmqRnxvQMunLKMHwiqleCu2+e67M2rA90KErYPDx6U1cIq /GDapPuDto7CwRcTAoNrJfnqmbu4dNIycZK5aFc= X-Google-Smtp-Source: ABdhPJyNt9uxXOtuVQ8fehvR+Z2PCMeG2NBbahm17SLLN82137ejKfDdWRRGzGoL78ZHu442ZclQAeBawG6FITXkWUY= X-Received: by 2002:a5d:6ccb:: with SMTP id c11mr12323wrc.122.1614288999826; Thu, 25 Feb 2021 13:36:39 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 25 Feb 2021 22:36:28 +0100 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000066460505bc2ff2b9" Subject: Re: [PHP-DEV] [RFC] Static variables in inherited methods From: glash.gnome@gmail.com (Glash Gnome) --00000000000066460505bc2ff2b9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I can understand that some people coming from C++, Java may be shocked by the behavior of a static variable in a static function. And the need to improve things. Maybe can you add *virtual static* keywords as a replacement for old behavior in your RFC . You would satisfy me. class A { static function Counter() { static $count =3D 0; virtual static $i =3D 1; return [++$count, $i++]; } } class B extends A {} var_dump(A::Counter()); // array(int(1), int(1)) var_dump(A::Counter()); // array(int(2), int(2)) var_dump(B::Counter()); // array(int(3), int(1)) var_dump(B::Counter()); // array(int(4), int(2)) A::Counter::$count =3D 665; // Great Feature A::Counter::$i =3D 0; //Initialize B::Counter::$i =3D 0; //Reset In C Poo we could get : /*header*/ typedef struct _A {// Instance class A } A; typedef struct _AClass {// vtable class A int counter_i;// php: virtual static $i void (*counter)(void);// php: public static function counter(){} } AClass; typedef struct _B {// Instance class B A parent_instance; } B; typedef struct _BClass {// vtable class B AClass parent_class;// B contains its own virtual static variable $i } BClass; /*source*/ int A_counter_count =3D 0;// What did you expect ? //... A_counter_count =3D 665;// php: A::Counter::$count=3D665; A_class_entity.i =3D 0;// php: A::Counter::$i=3D0; B_class_entity.i =3D 0;// php: B::Counter::$i=3D0; Best regards, Serge Le mar. 23 f=C3=A9vr. 2021 =C3=A0 15:02, Nikita Popov a =C3=A9crit : > Hi internals, > > While looking into various issues related to static variable handling, I'= ve > become increasingly convinced that our handling of static variables in > inherited methods is outright buggy. However, it's also long-standing > behavior, so I've put up an RFC: > > https://wiki.php.net/rfc/static_variable_inheritance > > Regards, > Nikita > --00000000000066460505bc2ff2b9--