Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124469 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 F1B381A00B7 for ; Thu, 18 Jul 2024 09:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1721296272; bh=BEDDvpDejOtEIQo1pJvVFUOzpQhmKXiwmoQqJYtE2/I=; h=References:In-Reply-To:Reply-To:From:Date:Subject:To:Cc:From; b=OEzhFL1H3MzO37dlhjz3B9GNZ03o0iNESeS45UHnsdfEteGFBK62NQJuk6BX07mMp AtuTTq5OnVF97D0FhVo1PnOK1/ecW5cRmRnl+B4xPHQmqiW6ZI11duWldGwAkxJgah XCxoUNZe+slXjMubEDz5D+I2v0x60fSdo2p+sCmYWN7GXSVvzVzGmFDEAo5ElpYfQF 6hNx27Aj2SIp1rCKeh3AaceZwV0Ijhz+PYXpdveHrk0pO0Pu+zzmo1DGykxiWhGwVa K9g3/J2Kr4AoRKOCFvEHd4nNQlkcV5v4UHilVfi6J6N0FSVOQ8YD19ukgu8l2FYOp6 WNoFiDxW6t0Jw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9577D180084 for ; Thu, 18 Jul 2024 09:51:11 +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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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, 18 Jul 2024 09:51:11 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a77dc08db60so63599266b.1 for ; Thu, 18 Jul 2024 02:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721296179; x=1721900979; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=T/wwWJ0Mn8zxTx9TwR3S2054njEqFUbVNdXUa/dxtqM=; b=eSw/Yfc/EGidBbliuJcF5laMln4AEZCaVuDm+kQOThFAZ9peqVHq9QNpD0n4Rlue9z xua+PIA93vbLFkcv+eTYpMDCw3V9ZKs9GnxFdvtAQaWTQZ2BLxd8yl+kLvLncxWmEKK/ GGXzk7AZkASOj0+EeKZ3EApegq137SGt19VvaitwdFEdRdBlswUAkkvjDaBC1ZKxwVjI sAAQDXrc7VfWxwaD1SwwhPF3kdeW/FUCc5MiI13WGEC/rPXvoQnodR/d59uW2Htv0JmT WkscGVOv+OvXfLX2lKlIdeNkmKKq3Xw3qlN32xSipfuGmcUH6WzXSlrFqVyjQUxGnC8L vdvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721296179; x=1721900979; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=T/wwWJ0Mn8zxTx9TwR3S2054njEqFUbVNdXUa/dxtqM=; b=lo5YKlx5jmNzOu6C+h75Nln2kCi36bzOoRPP7d0JWVrvx9dK7phavxtWFUW14ptBWi QrfbGOkx/nHWa11j+jGxsgjVgsfX9LvgJfblKt+6uwk/JYCB39Q/XgXAuh8bLnAGl6lq FExfI1aPEhXy2bTRS9b9Ruw2cryRhP1iI72UmZnoobnXfj0TH6VM1EnJQVJQ0Okiy81h tB7wEeuqNVMQXHgSzZs4dnKCpLINm0IDnqsOKvcn2QpgLcuK15vRsAodLAyde8ALzuQF 8Q3kTwmhErgnDjAmS5sJBcPLbR9GK11PLAlD93Yyzkbu/KbFWnea9HpwfXiscunieH3f tWfw== X-Forwarded-Encrypted: i=1; AJvYcCV/X1DUHJJ9BWaALRYWZmye/X8y4rRTIM9xSHALMlKNUzqhXNR4YUMHeryubZCmnopcNZzcJO7m7+Q7v7ADWzXVSXkKBzRE3g== X-Gm-Message-State: AOJu0YwzVv+jeKS8Gp78UsQtkdBxBfEpkcZXpxzDUam/31Yhixn3B7bh M4DCwgijPrEUu8iblVz5E+kPa3LNeVMxY9deF+E88uyVqtRkvcZdymtSpxNkOj7nF/YacboeYIs fNhpWJJ06wfC7qo0tmCbop1FXfAI= X-Google-Smtp-Source: AGHT+IFF96zVSWCY03MzEiTlNwE4IHeE6V5tIFn/oRa+Rsivo3YvZeWWFsayETdFnMiizk+1SRQvilxfCt5RJ9zmrgU= X-Received: by 2002:a17:906:a84a:b0:a77:e58d:d8db with SMTP id a640c23a62f3a-a7a012f610emr306404666b.32.1721296178964; Thu, 18 Jul 2024 02:49:38 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Reply-To: lilybergonzat+php@gmail.com Date: Thu, 18 Jul 2024 11:49:27 +0200 Message-ID: Subject: Re: [PHP-DEV] Optional constructor body To: Ayesh Karunaratne Cc: Oliver Nybroe , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: lilybergonzat+php@gmail.com (Lily Bergonzat) I don't view this proposition as a breaking change. The way I understand it, writing an empty body for a constructor would still work, but we would also get the option to just omit the body altogether. I think it would be a very sensible update. I also think it should require a semicolon, just so we have the same kind of syntax as interfaces. I would love to see such a change! On Thu, Jul 18, 2024 at 11:46=E2=80=AFAM Ayesh Karunaratne wrote: > > > > > Hello internals. > > > > I am looking into making the constructor body optional in classes, esse= ntially allowing you to write > > > > ``` > > class User { > > public function __construct( > > private string $name, > > ) > > } > > ``` > > > > Currently to make this code valid, it would have to be written the foll= owing way > > > > ``` > > class User { > > public function __construct( > > public string $name, > > ) {} > > } > > ``` > > > > With the introduction or constructor property promotion in 8.0, we ofte= n see classes where the constructor has an empty body, and my guess would b= e that this will only increase with the introduction of property access hoo= ks in 8.4 which is allowed to be defined in the constructor also. > > > > This change would only be a cosmetic change and simplify the userland c= ode by removing two redundant characters. > > > > > > > > This would be my first RFC and I am willing to try and implement it mys= elf. > > > > > > Best regards > > Oliver Nybroe (he/him) > > Hi Oliver, > > Some links to previous discussions when this was brought up in the > mailing list before: > > - https://externals.io/message/114324 > - https://externals.io/message/111590 > > I followed those discussions closely back then, and I suppose the > general sentiment (to which I also agree) was that this is more of a > code style consideration rather than a technical one. Although it's a > cosmetic change, the fact that it will cause BC issues on older PHP > versions was a significant concern; now more so after we had > Constructor Properties for 4 years. > > I think you can gather more pre-RFC opinions from this mailing thread, > especially now that this is brought up after a while since Constructor > Properties were introduced. > > If you do with to go with an RFC, I'd like to see if your proposal > addresses whether this syntax should implicitly call > `parent::__construct()`, and if a semi colon is expected or not > (`public function __construct(public int $foo);` vs `public function > __construct(public int $foo)`). > > Ayesh.