Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123692 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 D74761A009C for ; Thu, 20 Jun 2024 08:57:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718873933; bh=TUKjxVknhh25YLk1KJ2NnS9/HlcSImD7EwXMAvVnYH4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ZfpTUaIGceiXQ8xn9gA0O769jb8wx0nsoVYom8XOXysO1d8P+sNe1Bhmh8WecBQSg S/NDLX0bp/wCsK76repAkEMDh0GpBmKY78dx+4ldmbT0l2eDrhfLT3QElucmnW+CTg VB/AdXTeOHauzRRu3Oq0xPiwYRzvrZcP+VK9LsQNvmpW+E4lftDWJs6VLoS34id3Vl z8pSTyO5psW4sRwfwn6nItx2z0OgG70pii0LveuFE5gvUHphSEj9/6niipCCbJRaVu 3f/rd5nGP3ojJxa7ZJPfXCJZvdFI/ZyQqRCdNARBG7xM3ay6gPeRImrPSY4jjMy/Nx 2Eo6qpYZH2ZBg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2574E1806AF for ; Thu, 20 Jun 2024 08:58:52 +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, HTML_MESSAGE,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-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 ; Thu, 20 Jun 2024 08:58:51 +0000 (UTC) Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-57d0f929f79so490039a12.2 for ; Thu, 20 Jun 2024 01:57:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718873857; x=1719478657; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Vz1E6U2zc3bqgJgJuyxXrR9mJ3Q0rzOjCXY96+coJRU=; b=dc4v1NyAcR9t1lOd+AOAhOzl/bx/FD1JwisNwX1YHIjnGte2Xfm0lNjPdoE1SkxPKo WdLsWFzAmjsseYAuS0oS/6dvCVGfQDOBjyr0ZIsxJIXTzkwvMAF9bZtR25fkR10/mWwr eHPNJGJRctFYQxs/mZREdFWd5hKEgYZxV3S9IMu0C2Prn3XvMCGYhPJLFd2DOE0gFH7+ BTzVZWbe3w5MYZ/1Vy+COMYFd908d7YKTbTf5HV+BKXjqDM9r9Bd1DcgV8GNuOhPdv5E fkcPh6gaxXutOcIzw7AkI3kGxsOqQf68gTMyZNtZsESXOiHGaByAAval5jH5ATJ/OPpi 31aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718873857; x=1719478657; h=cc: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=Vz1E6U2zc3bqgJgJuyxXrR9mJ3Q0rzOjCXY96+coJRU=; b=cEM4DYl92hp17oOlpqX6ve+kQNrhVLIDIAQ5veqBgF+zsREnVm5fBIFM348DJHGz6/ 60SLxaePTdsJ+yzLYZdX7Lv1/A4qlZ8IDxwND1R/lnd0KmSFIun3XcaE/CVi+t+/IwnS cCSOzBBVBtPnV0JyMRYLNKGsmxHhgct+4EwLnnfYkJWQzxhWFIws5F6QYsOzGjktbe+i Np9/LcVNT3RUrJs52SCRbEXkVWHyk2k0NhBywhBOe23xxmcZtp65CywwfCwFMGhuvzvP 4PxyQCxZH/LJH1WVhavoNYo32FwfhU7EVICiKjuR27aO70271+UMuiIlqjO/XfD4URGB tQww== X-Forwarded-Encrypted: i=1; AJvYcCXvMxcFQNdfZEzvEmJMdeBPJ5tiZC2qBuiBhcctVIy1tK7tIb1AoMLY80yesyatdHN92TeKLpaQaKfXfB7G3XA3mdIbUonvgg== X-Gm-Message-State: AOJu0YzCGUFbqX/l/qKyyixE1YGnAGgIeekkKzSsxGCXw193sLjTbOfT MN/k/BUSdP19tGLuKIyE5WPRaZ6SDpaQibSXXsOzOEzELvn3a8zdKHWuDE4ZLYHjO2YOQmxa+04 4c/WdPcS4PjIywa20CGmQukR0SsM= X-Google-Smtp-Source: AGHT+IGGy4Cat1PuuQgUfZpSF0cBpWAd0r8ficc97kDx4bD77eKTobOuMAadl9zjwdxA94wFnRC4hC2u+G74iytGOjM= X-Received: by 2002:a50:8e09:0:b0:57c:fd20:352c with SMTP id 4fb4d7f45d1cf-57d07eb5387mr3121419a12.34.1718873856445; Thu, 20 Jun 2024 01:57:36 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 20 Jun 2024 10:57:09 +0200 Message-ID: Subject: Re: [PHP-DEV] [RFC] Static Constructor To: Mike Schinkel Cc: Ilija Tovilo , php internals Content-Type: multipart/alternative; boundary="000000000000a09556061b4e81df" From: kjarli@gmail.com (Lynn) --000000000000a09556061b4e81df Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jun 19, 2024 at 11:57=E2=80=AFPM Mike Schinkel wrote: > On Jun 19, 2024, at 2:36 PM, Ilija Tovilo wrote: > On Wed, Jun 19, 2024 at 2:34=E2=80=AFPM Erick de Azevedo Lima > wrote: > > New expressions continue to not be supported in (static and non-static) > property initializers and class constant initializers. The reasons for th= is > are twofold: > [snip] > For static property initializers and class constant initializers a > different evaluation order issue arises. Currently, these initializers ar= e > evaluated lazily the first time a class is used in a certain way (e.g. > instantiated). Once initializers can contain potentially side-effecting > expressions, it would be preferable to have a more well-defined evaluatio= n > order. However, the straightforward approach of evaluating initilizers wh= en > the class is declared would break certain existing code patterns. In > particular, referencing a class that is declared later in the same file > would no longer work. > > > Lazy evaluation might be ok if order is clearly defined. > > > Consider that some uses for a static function need to always occur no > matter whether or not any other method of the class is called. My previou= s > email [1] covered several. > > Here [2] is a discussion on StackOverflow of "hooks" that should be > eagerly loaded. > > Thus I think it important that if lazy evaluation is used for static > initializers then it should be an option, and ideally one that is opt-in > vs. opt-out, e.g.: > > class Foo { > private static lazy function __staticConstruct():void { > // Do initialization stuff here > } > } > > > -Mike > [1] https://externals.io/message/123675#123684 > [2] https://stackoverflow.com/a/2400206/102699 > Seeing an extra keyword made me think of: ```php class Foo { public constructor __construct() {} public destructor __destruct() {} public static constructor __construct() {} public static destructor __destruct() {} // probably doesn't make sense right now } ``` This syntax would allow named constructors in the future, or even omitting the default name. ```php class Foo { public constructor() {} public destructor() {} public constructor create(int $id) { $this->id =3D $id; // no need to call the default __construct, nor needs to return } } ``` Not sure if this is even a desired path to take, just wanted to throw the idea out there. --000000000000a09556061b4e81df Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Jun 19, 2024 at 11:57=E2=80= =AFPM Mike Schinkel <mike@newclar= ity.net> wrote:
On Jun 19, 2024, at 2:36 PM, Ilija Tovilo <tovilo.ilija@gmail.com> wro= te:
On Wed, Jun 19, 2024 at 2:34=E2=80=AFPM Erick de Azevedo= Lima
<= ericklima.comp@gmail.com> wrote:
New ex= pressions continue to not be supported in (static and non-static) property = initializers and class constant initializers. The reasons for this are twof= old:
[snip]
For static property initializers and class constant initi= alizers a different evaluation order issue arises. Currently, these initial= izers are evaluated lazily the first time a class is used in a certain way = (e.g. instantiated). Once initializers can contain potentially side-effecti= ng expressions, it would be preferable to have a more well-defined evaluati= on order. However, the straightforward approach of evaluating initilizers w= hen the class is declared would break certain existing code patterns. In pa= rticular, referencing a class that is declared later in the same file would= no longer work.

Lazy evaluation might be ok if order i= s clearly defined.

Consider th= at some uses for a static function need to always occur no matter whether o= r not any other method of the class is called. My previous email [1] covere= d several.

Here [2] is a discussion on StackOverfl= ow of "hooks" that should be eagerly loaded.

=
Thus I think it important that if=C2=A0lazy evaluation is used for sta= tic initializers then it should be an option, and ideally one that is opt-i= n vs. opt-out, e.g.:

class Foo {
=C2=A0 = =C2=A0=C2=A0private=C2=A0static lazy=C2=A0function=C2=A0__staticConstruct()= :void {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // Do initialization stuff here
= =C2=A0 =C2=A0=C2=A0}
}


<= div>-Mike

Seeing an extra keyword made me= think of:
```php
class Foo
{
=C2= =A0 =C2=A0 public constructor __construct() {}
=C2=A0 =C2=A0 publ= ic destructor __destruct() {}
=C2=A0 =C2=A0 public static constru= ctor __construct() {}
=C2=A0 =C2=A0 public static destructor __de= struct() {} // probably doesn't make sense right now
}
<= div>```=C2=A0
This syntax would allow named constructors in the f= uture, or even omitting the default name.
```php
class Foo
=
{
=C2=A0 =C2=A0 public constructor() {}
=C2=A0 =C2= =A0 public destructor() {}

=C2=A0 =C2=A0 public co= nstructor create(int $id)
=C2=A0 =C2=A0 {
=C2=A0 =C2=A0= =C2=A0 =C2=A0 $this->id =3D $id; // no need to call the default __const= ruct, nor needs to return
=C2=A0 =C2=A0 }
}
```
Not sure if this is even a desired path to take, just wanted to thr= ow the idea out there.

--000000000000a09556061b4e81df--