Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126435 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 1EFE01A00BC for ; Tue, 18 Feb 2025 08:00:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739865465; bh=8DFpsQnF1jYD/F6N+kf4AmDJm8+ce26fIBYbN7j61IY=; h=Date:From:To:Subject:In-Reply-To:References:From; b=myTLkhwLIMsiEkk7WueKFZ436mcF82CHdDE3LUiGTw08GlV5D6BNmWNBilHMVGBtV Sx0Sp1cbA3RNSqU2vR8AJ376ezHmLdmEy7Y5Vp74qCwzDqW/gSLwQGZbZzkRtF1wFq Oy3NXIsUH53KN63whNy/0L+Kb+SmOuGpZivKSHYaKK1H6rhNQ24ihl9/fKyeEIk/95 BG6Q+VL0Xxn/S1Lz46t9336bc2egURlVFtIsiOqLeLQhsbJHlSZgBykoQWXAUSLqzl ItOcRB9lgAlK4ezVxMr1aNXk6f1gd8kDfhMei8eHsD9aLrgxaki2u414GywDCQUzqk +BdFlFg46J4dw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E34BD1801D4 for ; Tue, 18 Feb 2025 07:57:44 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-b3-smtp.messagingengine.com (fout-b3-smtp.messagingengine.com [202.12.124.146]) (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 ; Tue, 18 Feb 2025 07:57:44 +0000 (UTC) Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.stl.internal (Postfix) with ESMTP id 55178114016B for ; Tue, 18 Feb 2025 03:00:25 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 18 Feb 2025 03:00:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1739865625; x=1739952025; bh=8DFpsQnF1jYD/F6N+kf4AmDJm8+ce26fIBYbN7j61IY=; b= Ytw4+okw8cD7d2XEwGh5m1z3FxIXluuhIEzeVzVysRTjzISBWaIhzxKdjuNQu1tg 3kQalz1jamNYKRiJjp6zupIA5t1nkRuclNoZcDjN+zPZH5Zv6Pfxsef0XqlH0fuB Oj+Ha67u8V90yUJhSteykpc8BwZeYGnQePNrdkh1qqt2446iwFKa5UNZCIMBb9ot 0MuUxvDVt+KSWwdDMzTr6HL79Gi6tc/1AQgaiq5W16PzrZDO3DLSdERv99xgMViK O+LhmCOxLLQx1bKv8bUOPxwzGm+xhtFb+nfYZ9GtcFx/x2x0aS5+XZQIBgNRvyT3 f5Li2H5rteRq/ej8YEWkxg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1739865625; x=1739952025; bh=8 DFpsQnF1jYD/F6N+kf4AmDJm8+ce26fIBYbN7j61IY=; b=R4UJNL3DSjfNR8lTT nYGwR9fqZd0gfDE3jaz27SxCO8viAvYBYB44Svlvr7SfItBjyvWonfSDKI6xBvD2 QodDXIuFbVx1xLnjdrdTtWN8wncyN8nRjjPna3pGl5siRAYjfYyCLer1u1NbHwbB aOME/0RZ0kXfL/JsY0kLxkPFJcQSU7/CVG0Q6Sq7CpXoM5Ued4eMmgrEhW89Tsfm Y7uwds6aZoLBiPTtrW+tjRhuM0hckF2XBrgt3+f8SihiSghBoaa5OLzltXNj+Hak z2hpbeODe4v1/oT3Apx2uhvkFmfAGftuufCe17yfGiDHJRmzpHbDZWDQ7O0r4YJ3 WJbqA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeitdejhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fufggjfhfkgggtgfesthhqmhdttderjeenucfhrhhomhepfdftohifrghnucfvohhmmhhi nhhsucglkffoufhorfgnfdcuoehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqne cuggftrfgrthhtvghrnhepieejfeduleffffehuedtgeeigeetieetvdeuiedujeelkeej kedvgfefffeuffdvnecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphhhpsehr figvtgdrtghordhukhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpd hrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 18 Feb 2025 03:00:24 -0500 (EST) Date: Tue, 18 Feb 2025 08:00:22 +0000 To: internals@lists.php.net Subject: Re: [PHP-DEV] Concept: constructor overloading syntax sugar User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 17 February 2025 14:39:42 GMT, Viktor Khramov wrote: >Hi! > >The point is here: >https://gist=2Egithub=2Ecom/vhood/665418835e65be26d5a818fded92ab75 >Static functions look awful and break the object's API=2E Personally, I think quite the opposite: named constructors make a lot more= sense than type-based overloads=2E For instance, you might have both creat= eFromJson and createFromYaml; their inputs are both going to be "string" as= far as the type system is concerned, so overloading would be useless=2E Swift gets around this using "argument labels" which is sort of like requi= ring named arguments and despatching based on those names, but I believe is= actually derived from SmallTalk's multipart method names=2E Delphi is more explicit: a constructor is any class method marked with "co= nstructor" in its declaration, and the name "Create" is just a convention= =2E It does also support overloading on types, so other names are rarely us= ed, which is a shame=2E In your example, instead of this meaning different things based on what $a= happens to hold: $decision =3D new Decision($a, $b); You could write one of these to be clear:=20 $decision =3D Decision::createFromId($a, $b); $decision =3D Decision::createFromMail($a, $b); Even if someone were to come up with a working implementation of overloadi= ng in PHP's type system, I would probably oppose it, because I think it mak= es code harder to read and reason about=2E Regards, Rowan Tommins [IMSoP]