Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123686 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id EDB6B1A009C for ; Wed, 19 Jun 2024 18:36:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718822248; bh=sD9AnZ6LKEKiocsQP4QkE8CQsj8RdpsfHba5v1xmKTM=; h=References:In-Reply-To:From:Date:Subject:To:From; b=RiQuWNsR+Bb/Jd8jgwxAGDFZIk/T9I+BfsQS5InYddkpZlMcRdT6e09baTN4gUvoY P1GZ0XiRdf08Wy+VX7F8vYvMQmswAxJIrHdOAPO/BdLTWi7ahjJCy0EelKOOpgetAf 5MjbgMXA5erLm+aXJi7lZtyiilBwsmDS852SYUAaZUB2PVqSpQwjJA8m2OHbGCYsAh rPI5XiRbwqli5Jnni2zS3sJsbF9TjRuKV4rq8BG3YwpB8n7tWlVa6SkiuJmHxR6yBq 4isaqBpdDXYRC7BymQjdW4OZBtzcCWifURoHB6RbP1guP+pPAP6Aoi2BOz1JMzAEea uCIC9D5Zpbfxw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 38850180057 for ; Wed, 19 Jun 2024 18:37:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 19 Jun 2024 18:37:25 +0000 (UTC) Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e02b79c6f21so60778276.2 for ; Wed, 19 Jun 2024 11:36:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718822171; x=1719426971; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sD9AnZ6LKEKiocsQP4QkE8CQsj8RdpsfHba5v1xmKTM=; b=mCDckBz2y5I414zSOxduAVWa7EnrkYTfVNdVJr9HPk+3cz0Y8MwiBbZl8OQlkR0bKJ pz0UeRKN6gp2xd3UDYWZGAXcbslBqxMhOZPYOQE/32rsKQo/CzExVoftbaluffVD2CmU 4tFSZxeHoxnDgUJRIkNWkMhTqxFsa5GH15++KR78/wYc4CUw4pKeFdrrz77watqmrm6t gUcKZ427U2j3xOzIswgU3MjKOiaBxVkzS7VS9dakNG1EWQEwNZwQL5Rd1MirDkrFxXLY k8hHKXM4Ao6jcse62Ur90qoiF9Rnxrh4AO69l2PDINaGWFj48R16zfuTglX4858mbz7c UefQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718822171; x=1719426971; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sD9AnZ6LKEKiocsQP4QkE8CQsj8RdpsfHba5v1xmKTM=; b=u2+cB+Qwa1jHh4Vp0xUMHqbTkz61REZfZvSO6nrBUf0tA3dHv680utKXZnrtgBKJyI fFCKtqEcRJokVnqZ9YG5uwidVb2qxoP21WBBg20k+LnY+UWXQayrndr41CY565KmnmaB LcI+DDQrFFCcTaC/p2Gj2YsnL7TXxhBIlAEwaPnQHqevqBsCucApyqmepnYbQLf3c5CC lQ1v08FaFUtorOVIjV2RrE+eakTODGFSmWxsFxa/dZw/k0lP6JebTqesB34JhhiHR3Ub 5V8onSMzN91lJ9dxMU1FngV3lU5ABVDS1TETbq4Y1Nil3jItOnm++006aInK0msbEV5S EL4g== X-Gm-Message-State: AOJu0YykDzJmztxvlKeQkoWsqx7GX8QZ6ISeLTlygi50vvKeXOxcRxSY sC9DWWqnuO1tW5pEuw39j9TQj4HdCzcdoGkFeDUYGbIS3GRbdPwsJrYYRQV8XBt8bGl9WybagNr wLOsqqsxMJ+rdoCMjxNr1jup9BQiaKNgd17I= X-Google-Smtp-Source: AGHT+IFhlC6gJe1mHEH83iyd4UMchkzLOfdKl3MA17yhYRjuhDhLcVxql3hp+fKUOTvCX2mj8+KIZk2iYTlstgZpS5A= X-Received: by 2002:a25:bc41:0:b0:dfb:1e8d:1313 with SMTP id 3f1490d57ef6-e02be18f366mr3495580276.39.1718822171302; Wed, 19 Jun 2024 11:36:11 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 19 Jun 2024 20:36:00 +0200 Message-ID: Subject: Re: [PHP-DEV] [RFC] Static Constructor To: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Erick On Wed, Jun 19, 2024 at 2:34=E2=80=AFPM Erick de Azevedo Lima wrote: > > You can read the RFC here: > https://wiki.php.net/rfc/static_constructor I see that you're using zend_class_init_statics() as a hook to call __static_construct(). This makes the initialization order unpredictable, because static properties are initialized lazily when the class is first used (when instantiated, when accessing constants, etc.). Essentially, this recreates the same problem described in the "new in initializer" RFC: https://wiki.php.net/rfc/new_in_initializers#unsupported_positions > New expressions continue to not be supported in (static and non-static) p= roperty initializers and class constant initializers. The reasons for this = are twofold: > [snip] > For static property initializers and class constant initializers a differ= ent evaluation order issue arises. Currently, these initializers are evalua= ted lazily the first time a class is used in a certain way (e.g. instantiat= ed). Once initializers can contain potentially side-effecting expressions, = it would be preferable to have a more well-defined evaluation order. Howeve= r, the straightforward approach of evaluating initilizers when the class is= declared would break certain existing code patterns. In particular, refere= ncing a class that is declared later in the same file would no longer work. Lazy evaluation might be ok if order is clearly defined. Making the order undefined makes it hard (or impossible) to understand which symbols declared in the current file may be used from __static_construct(). The alternative mentioned above (calling __static_construct() at class-declaration-time) likely breaks too much existing code (because it would also require calling static initializers just before that, which may reference symbols declared later on), and is further complicated by early-binding. I'm not sure what the best approach is here. Ilija