Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117850 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73982 invoked from network); 3 Jun 2022 12:50:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jun 2022 12:50:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1B68A180382 for ; Fri, 3 Jun 2022 07:35:32 -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,RCVD_IN_MSPIKE_H2, 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-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (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, 3 Jun 2022 07:35:31 -0700 (PDT) Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-2ec42eae76bso84216157b3.10 for ; Fri, 03 Jun 2022 07:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wjdgCgvDaRCwHltoQ6VVl1WD09KV4hWjfnEoZWs1Q5w=; b=PdeQ4esQIPQOW3iluGwrZSdipoER+ZniQ1CDMB+D4YVuTuqehHHLasINpmITDam3VX FcbXgIM/FnDNHRnKN3jcIRpb6a3EBn7QOVDIHjIJ/MVCt7uryfzKXwuBkOJd7xYmVk5g g+FjpQqLOD4x7imtkf4Y0i68ilC9ooPPNeYUR5zIoWNT5dLy+E/thdnzUBn4d8qiEFYr puioRntHN9tYuKbbb2uQ8MWhuPyLGPf388icfx3zw5CGW15lle+kHkri9bH/DxsawLK9 mz4RAARse+iG3znPZXXHtTn08qwTuqJ9Tb1xTdSbER/5AtI5NFYJgYMfiAhz+4vzefqO 25Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wjdgCgvDaRCwHltoQ6VVl1WD09KV4hWjfnEoZWs1Q5w=; b=hK5soxR6iZV0sfN5o8/KPR4nNdnHm7boQgMe9w5wK1CXqiedg4QnxAFCdQ98A2xi+X bNEKx0rzA5nYYjKJJT3ESWfNMfYe36DJ09kpmeIlUsau6SygwYX5c1OPIM9Ix+33ajDt c8VRLOdl3lZEhdHLBJ8TBsoUpVHxYvzjVGEDAzfOZxZZXoFVHGTp3MO4qe7j8pXk9k9f JEvhhkg3bladw+wvOwggLlWm1UWo1IARgftUVbbiUkgrr2qTHwvDDSqJPdjEOae6haND 0yN7f+XfKSn7FKrg5kmmx+zOq5vhm1mUPc+CVhU9YITQKf0qWkcTh+eaOP5Ljhheuebm fivg== X-Gm-Message-State: AOAM530orXI0AcpzaZIYnGr0T4WoQjEhPI+ATc21aL5mQgVfnjxQ3/Bn geqK/Yl4LUjsybZ1SWiDP7aIhJiGrSoFAtrXTQ== X-Google-Smtp-Source: ABdhPJwDzFp+JO1kLh83qOATm46lRByuroOHyZb3gSdoAamPTU3Lm+raSuhueZF9IApZu76gja5DqpLkmpXhdVHvM9I= X-Received: by 2002:a81:c54a:0:b0:2d6:435a:5875 with SMTP id o10-20020a81c54a000000b002d6435a5875mr11418611ywj.181.1654266931246; Fri, 03 Jun 2022 07:35:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 3 Jun 2022 16:35:21 +0200 Message-ID: To: Robert Landers Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC][Under discussion] Fetch properties in const expressions From: guilliam.xavier@gmail.com (Guilliam Xavier) On Fri, Jun 3, 2022 at 3:26 PM Robert Landers wrote: > > So, how does this change our mental models when writing PHP? For > example, I generally consider `const` to be a "compile-time" constant > (ie, generated/created before any code is actually executed). So would > this allow code to actually execute before any other code (ie, by > putting code in a __get()) and thus cause issues due to database > drivers and etc to not be loaded yet -- or cause them to be loaded > prematurely? True but that's already the case since PHP 8.1 and https://wiki.php.net/rfc/new_in_initializers (https://github.com/php/php-src/pull/7153), e.g. https://3v4l.org/MSWi0: ``` class Foo { public function __construct() { echo "Side effect!\n"; } } const C = new Foo(); ``` but as https://externals.io/message/113347#113607 says, "side-effecting constructors are a terrible idea", and same can be said for "side-effecting [magic] getters"... Also note that this only concerns *global* (or namespace-scoped) constants (which can also be defined "dynamically" with `define()`), not *class* constants. -- Guilliam Xavier