Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112008 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77885 invoked from network); 5 Oct 2020 17:00:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Oct 2020 17:00:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DE3C91804C6 for ; Mon, 5 Oct 2020 09:13: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.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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 ; Mon, 5 Oct 2020 09:13:35 -0700 (PDT) Received: by mail-ot1-f52.google.com with SMTP id l4so5670085ota.7 for ; Mon, 05 Oct 2020 09:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=3bvNJNKv1FFhYjJFSyyT5ZZ4nIgxQmY6tGZ1wYj0pHw=; b=O9Sv+q9TKTmTXfJyu99n/JtWRJ0ANNa2nmlaZ9omAEjc58X+gkL5QUH8VsnhCaay+6 gVVzLhWmEYYZ+0L0uNkE/MptFSexJuul4ieRVewYxsPHXUtNaukYmf2TipMnZhg3PjzM /17g23UoS1Z9u0Vw2aPoaCQEgc7Tpm7kDiiI7okAzHrerAfcoNiAakpSAzc40tJVg75s kJnXhcIAnqlj4R6BBDrv70aATxxewIb4x6b4zg3zy8IDu9fhC/blkcPBMsdW4idFf7ny gO2yhvqzHmWpQdRq34VO3uYWxpo/SS+y/znm6ZQGCC90/tGMqSpbHM7xUfDdeA8DSNyq ER+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=3bvNJNKv1FFhYjJFSyyT5ZZ4nIgxQmY6tGZ1wYj0pHw=; b=tC0TUMSopVM3m1x8SeScc7saeuN9Z6STk6qhpwFA15vyryDQoqDkPV1TyLht8wBu38 w6RCyZ997/qV3Yn4gelin7NUPz+Gh2GD2+kHB4YzlAby1FCG76DWLVFGh6S/wBgg2n9u 5Gv1/oHhMqSC5FUeIBnkX281DinfbdKjKF1w7FfYEaN9tHJyL4wNto3GWLA7yX+89ktL AKeCLyUweERxGKppO0HN13JRKHpYzsCG7HDKzpgWhrSy0mWtp9la5eJUBdZj8s+e7A1Z 7EN3g7k036knzgJGA5zkiPmv95SCwtF0OTLWSOhKUYJHGVSC7ygtq0q6tYX4/j2rUw6A h1nQ== X-Gm-Message-State: AOAM5322Am2nBYC4ZvZllO2cORK+gB5atrAxAs5CAAiCeJf9bmhcE+n0 /y9RcccrRUGDEXB2a/DdS19qcr0oJfV08N5VvVy+1doKHOKXBg== X-Google-Smtp-Source: ABdhPJzABg5szuQfRIAKt99hxtQ8pShcZZll2AcFtbv021jr8kuw4PpoZbOV6veJIRMZ+gHuG2Ko2DLJcqino25Rsgo= X-Received: by 2002:a05:6830:22eb:: with SMTP id t11mr77372otc.114.1601914412115; Mon, 05 Oct 2020 09:13:32 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 5 Oct 2020 13:13:17 -0300 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="0000000000007ead3305b0eec33c" Subject: static vars must allow expressions From: david.proweb@gmail.com (David Rodrigues) --0000000000007ead3305b0eec33c Content-Type: text/plain; charset="UTF-8" Hello! I would like to suggest that static vars must allow expressions too. Currently it only supports scalar values, but different to consts, it could be manipulated by its own function that uses that. https://www.php.net/manual/en/language.variables.scope.php#language.variables.scope.static Currently you could uses like: function test() { static $x; $x++; var_dump($x); } test(); // 1 test(); // 2 So my idea is allow an initial value to be defined by a more complex expression, like: function test() { static $configurationHandler = Configuration::getInstance(); $configurationHandler->doSomething(); } Additionally, I thought that it might be necessary to implement some new methods for ReflectionFunction / ReflectionMethod, in which it allows to reset or check the current value. (new ReflectionFunction('test'))->hasStaticVariable('x'); // true (new ReflectionFunction('test'))->issetStaticVariable('x'); // true (new ReflectionFunction('test'))->setStaticVariable('x', 123); // void (new ReflectionFunction('test'))->getStaticVariable('x'); // 2 (new ReflectionFunction('test'))->unsetStaticVariable('x'); // void or (new ReflectionFunction('test'))->getStaticVariable('x'); // ReflectionProperty (or ReflectionVariable) One of the questions that can happen is about the context conflict, but it already occurs: class Test { public function test(): void { static $x = 0; $x++; var_dump($x); } } (new Test)->test(); // 1 (new Test)->test(); // 2 Note that $x will share the context like a static property, even if it been called from a non-static context. Atenciosamente, David Rodrigues --0000000000007ead3305b0eec33c--