Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126429 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 6F5C01A00BC for ; Mon, 17 Feb 2025 14:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739804161; bh=ah+LbWZIr3HEZMKpfqw6QL0w8m1wwWESu0bMeSb/gps=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=nWQse5R2Jd4wfoRasZlUU2ZzMbYV6B0UCrWyUqGwqcxn/+Ur4+9K0/ywAfZo2mpYF iy1d8tASknPrOxMUSgvQHHOUc7tkkOw2v8VYU/Feqb2bxmRjup7/J8VOq76kCRQKOq fsuFbElP3tVPAPhn7+bL3QIckk2zs6Fk69AW6gtEg8PPhpk0HLSkr2hmDEVZ4B4Cac JaLOYNOo9EXPfG8JC4YA3uqf50DyVYFZZvcLClBFvH/J958yDPpqk77xb/qnLP9nQa sP01u8RXoe+KBxLCCS9dD94ueGN75SKPZxvBKycKmKhHDVe/pc+bFQ6Jj52S1uMRRV LxLbXtKmvdnqQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2A57C1801ED for ; Mon, 17 Feb 2025 14:56:01 +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=-2.5 required=5.0 tests=BAYES_05,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 autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 ; Mon, 17 Feb 2025 14:55:57 +0000 (UTC) Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-6efe4e3d698so40236067b3.0 for ; Mon, 17 Feb 2025 06:58:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739804318; x=1740409118; 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=JGR61HzMbVhkwVfYPe59B+CIeMX2csD1zTYnBcFv87s=; b=dqIIg1D6KRKgTppYGU0Ht1+TIrshrtlfhfg6y9BEMacJqDhlEDwlEQ8IewVTKjtF4I 6KKmp12XYsywwq9ISAsVd/ny8cMtFDopfzJzelxnM8+CDjxBxspckD1hY9AGcsJoGqCZ /6F5/tmNk98zAutyylX83EUAA2mKk+xf/nsu+WyB/fupJcaKEABKRm2eOiazAv6e4rCr P5RfBPrz99dWQe7zhC1fsJqgbOoqX6tUHjXlQY+0i+pBNzrEBJo96GIDzhds+EwW+T+j USpv/DjrIT769hIT4qD1m+DXWMhTVhMk6tbBo50mbxt6k0IKfA7kI4hnw62dJyJhfRO0 v7+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739804318; x=1740409118; 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=JGR61HzMbVhkwVfYPe59B+CIeMX2csD1zTYnBcFv87s=; b=ZUjuOaizRX7qO7tBmvVw6fiyeR0W6QFL3adl9F1J/uZ0fXy2O9oBQS2gSLoOPAjdHX j6UosejwIUe29FQx9HF7IpVtXYhVoKPRCp2Oojz0cYbp1vbsPe2GXOP30U0VPYuvuDeV N67PQIYxD3oR5ldMTh8BlvD5C5EXKLkigWQsV52QEEV3QGsc7JH0+JivWCS+KD0sfnRk a9bfug/g6utGP0Lg10ruBGhmeXumfnL043etfymH7HMKL5/i3ywKo9b5WpKJHURnKB5U QiH2c2+DeVCSONpnI0/jGlo+1U2vWJMhs/uM8QhwOwHc/no/mldZpxY8PNzc+Z/vQZHl bHkw== X-Gm-Message-State: AOJu0Yy9UATsDNvWhjagbc1Q/GTJ1uwnc3gseqmdICnxYUsLv8yzTxVr /9oAHnxeUWFHoU1NYt5SzWC+b/TpMvHq3kWh/t7j863D8PPxsO6He4q0FHVHqNl8nkCZ7U5pX6P fLq9kqG7oh332G5fUlKvyqOa5M/Y= X-Gm-Gg: ASbGncvajZ/kqdp1MH4TP3epe9/AX/w5x0e/b7qRVPQ/CjphOyGL0kY2DYHBjpJIisu tF7ZU1eaD+rIKpWLq8H9zB+3aDtFgZeEdM0SjbHq1LgUb+Vx2KSSqZFTF4rSHSo3qatHXCsk2 X-Google-Smtp-Source: AGHT+IG6qFaSzj4oRKY4vPh4rx8zPrpmrdTo/ntjPNx3dXu9b0CbG5643qmpBRgICXuIDqhiSzVYVrb2m4pa0Mn7GFE= X-Received: by 2002:a05:690c:30f:b0:6f9:7801:7b2b with SMTP id 00721157ae682-6fb583a1865mr79774017b3.35.1739804318053; Mon, 17 Feb 2025 06:58:38 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 17 Feb 2025 16:58:20 +0200 X-Gm-Features: AWEUYZkBa04S24jzOSsCBSplZ04R7FxFlee9CMDSO-eOb-Jw3JUN_8-87w3LJPs Message-ID: Subject: Re: [PHP-DEV] Concept: constructor overloading syntax sugar To: Viktor Khramov Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000005b40c8062e57c20b" From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --0000000000005b40c8062e57c20b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Viktor, On Mon, Feb 17, 2025 at 4:42=E2=80=AFPM Viktor Khramov wrote: > Hi! > > The point is here: > https://gist.github.com/vhood/665418835e65be26d5a818fded92ab75 > > Is it possible? May I create an RFC for this? > Already possible like this: class Decision { #[Main] public function __construct( private readonly Uuid $id, private readonly string $comment, ) { } public static function fromEmail(string $mailSubject, string $mailBody): static { $id =3D preg_replace('/pattern/', "$1", $mailSubject); $comment =3D preg_replace('/pattern/', "$1", $mailBody); return new static( id: new Uuid($id), comment: $comment, ); } } Related to overloading, that is binding to the correct function in Java/C# at compile time, and IMO is not matching with the dynamic nature of PHP. I think we're not losing much by not having this feature in PHP, but feel free to think more about what the implementation would look like. -- Alex --0000000000005b40c8062e57c20b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Viktor,

On Mon, Feb= 17, 2025 at 4:42=E2=80=AFPM Viktor Khramov <dev.999.victor@gmail.com> wrote:
Hi!

The point is here:
https://gist.github.com/vhood/66541883= 5e65be26d5a818fded92ab75

Is it possible? May I create an RFC for this?

Already possible like this:

class Decis=
ion
{
    #[Main]
    public function __construct(
        private<=
/span> readonly<=
/span> Uuid $id,
        private<=
/span> readonly<=
/span> string<=
/span> $comment,
    ) {
    }

    public static functio=
n fromEm=
ail(str=
ing $mailSubject=
, strin=
g $mailBody): static
    {
        $id =3D =
preg_replace('/pattern/'<=
/span>, "$1", $mailSubject);
        $comment=
 =3D preg_repla=
ce('<=
span class=3D"gmail-pl-s" style=3D"box-sizing:border-box">/pattern/&=
#39;, &qu=
ot;$1&quo=
t;, $mailBody);

        return =
new static(
            id: =
new Uuid<=
/span>($id),
            comment: $c=
omment,
        );
    }
}

Related to overloading, that is binding to the correct function in= Java/C# at compile time, and=C2=A0IMO is not matching with the dynamic nat= ure of PHP.
I think we're not losing much by not having this = feature in PHP, but feel free to think more about what the implementation w= ould look like.

-- Alex

=C2=A0
--0000000000005b40c8062e57c20b--