Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129632 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 lists.php.net (Postfix) with ESMTPS id 60E871A00BC for ; Wed, 17 Dec 2025 11:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765969791; bh=fv1XPLZ1VwFw6mzI5xU7zVEjDMbyBDP1yka4h3i6x/8=; h=From:Subject:Date:References:To:In-Reply-To:From; b=FfuEbWXbJCBgmpfLGt7xpdObRB4awl7XXiBMC2vUE8uXuuPafucKdfgNC5cyRQwPu 6/IaFxWf75BwNfeE4RGJGd6abTBgNYbn1haC8H39EgohX78K5WXARHMp7i6Ji+1PSl HV5RyGoTxVHJAg1JucGo4IR9s+7vzCcJy8Fy8/JhL3ZDuyufTVoClq3rN1nuRnUhu3 7mYGJkWKaIV465EuYALhU6AUa5YsrTCC3NGg2UFtnZ2POsvxhCAr8M6RhYnuYwdfi4 eSWaph3l1Y4Hq+PFKn1E3KI99/M3QJXOQMURYddIEQbMdd5r3EiKck9EiHzuC+Htns pfBG9lTotUEFw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CD07B18007E for ; Wed, 17 Dec 2025 11:09:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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, T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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, 17 Dec 2025 11:09:47 +0000 (UTC) Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-47774d3536dso4691565e9.0 for ; Wed, 17 Dec 2025 03:09:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765969781; x=1766574581; darn=lists.php.net; h=message-id:in-reply-to:to:references:date:subject:mime-version:from :from:to:cc:subject:date:message-id:reply-to; bh=MWk0EsjO58Ee+hLO91m7hWz4U0K1QMM7V+unV1i7OtI=; b=EFNzXZ4KWDxJsi1cbXsT1AtmgRXixvShLyu6u7fVrh5iczLoIOS3/tKkWV0/zYL+CB u9Kh2lp/KidKlofmUK4XHR0XZYqLplCCqktrwSN8aeCmbdUAEAzVNRJPTvZoRIS3RP1r oGKrdJv4vnc8609962eXtjS314ymCjRLdS22pGkhsxRtSLCn6IoeO3G0FTMwh3g4E1Yv mjzVBIeg1CNfcvPLDVZiDTEUzlGlMC/Lf6n0kGOHTvlJepF9MTfNXFttrGVf6vELTx7W zOVe7e5Ot5DpRgdHhr7EHp/1N9Jna7m1+CusxK0uhRPpyMQcAzxBGe4OOLJD+0dai7JG zyUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765969781; x=1766574581; h=message-id:in-reply-to:to:references:date:subject:mime-version:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MWk0EsjO58Ee+hLO91m7hWz4U0K1QMM7V+unV1i7OtI=; b=rtI6678wKGNDQa15LsBGc8ebt3BEN7GfBiEe7Ek27ALS8dzgcHKjSgMJCpDiVvL92z /kfkL98uctJvnJ/D9OuNSXs4C5yHIyAGW52CItff2SMpBSRnsmRpPwzbdy/qZr2ZhMRn 0zZEShfXlrYgJ/qRhpe09j1dlaGwJXZsk0rmeSKzoiMjxM+JzutgDEf+OVUiBipCBtPL 3n7vKa8IhiJSk41jo+QRpDZN6nbF8i+5RMjpJG5NL0iV3yCgmPBFYpusrGXyKuu56NkU NwCwEzsJ2gXzDo29bPiOZO9iAt0iH1jrPj/3eQpprsAtJtwjZsg9HKx+h+4kGP+mQ4l5 mSOA== X-Gm-Message-State: AOJu0Yw+lwlgtUa1+1pYg9eINytf8ES9VclYwnMpXoS9pZtYO3hx0uEg b19iIAl7TWM3oORCe1RhjYPsegc1bSWIyOO0+xSDJDzNufKHj6L/GQSEZSHbIL1u X-Gm-Gg: AY/fxX4XO690QtttY2Df8WZNyQFyY6uQjRmrUIgPWXUlFCnVk6bo1z0H8LDEbSsw3ey YJCCayU8XmA+jzxVw2hm1iE8ihCpLncMpLGvigYjNrRrdU6ohGJbB2HiaAgd3JkRvgbkuswj83B FUhK6evvyIgRtK+yTOy3y9Sws/oojZC7WGvMN0mpYFJSEKC8GmrYgKofxLa2rxKxl69wvZVKYBs U6BQERXBvGyxG+lbKRXFROVX20r9e49uK7YfAwekBobl6ZLL/vKUd++ck4vzDQKP2/EN5d3lkEa gPFRHT1jakwJFqwgIMlOJNsAd9U7DvBmAXSlGTPGC/puoAz5wNW+SH3MvMb7dzsZaDf9ujhtXfd B+A8yuBpz4fiP6pziVTVHaYxiMHu3qPzuvGDLzcty6CCYPEjwHoWnoGqpd0DHAaNEqbRSn7dgJm KnwDeuChb0AKEpMu3keGFHCeqfZ6BKWeYL+Ic= X-Google-Smtp-Source: AGHT+IH7nlVBObbqwQmUtONJ/pgN/Ok7B7N9i8WdDR2yDjgpA3M6JptaGQ1xpBQJYgW98Q9cQ+fO3g== X-Received: by 2002:a05:600c:3f0e:b0:477:9890:9ab8 with SMTP id 5b1f17b1804b1-47a8f094206mr176296335e9.3.1765969780841; Wed, 17 Dec 2025 03:09:40 -0800 (PST) Received: from smtpclient.apple ([178.134.17.116]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47bdc1efda5sm33543525e9.15.2025.12.17.03.09.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Dec 2025 03:09:40 -0800 (PST) X-Google-Original-From: Dmitry Derepko Content-Type: multipart/alternative; boundary="Apple-Mail=_365812BE-518D-4A99-9162-430A7D0140C6" Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81.1.3\)) Subject: [PHP-DEV] Re: Empty subject in match and switch constructions Date: Wed, 17 Dec 2025 15:09:26 +0400 References: <2A357F88-BAF4-41DE-8646-6BBBF4EFF6F6@gmail.com> To: PHP internals In-Reply-To: <2A357F88-BAF4-41DE-8646-6BBBF4EFF6F6@gmail.com> Message-ID: <933A73E2-682E-4617-A4CC-AF70E7D45583@gmail.com> X-Mailer: Apple Mail (2.3826.700.81.1.3) From: xepozzd@gmail.com (Dmitry Derepko) --Apple-Mail=_365812BE-518D-4A99-9162-430A7D0140C6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Feb 2, 2025, at 4:04=E2=80=AFPM, Dmitry Derepko = wrote: >=20 > Hi! >=20 > I=E2=80=99m thinking about making match (true) and switch (true) be = more lightweight by removing the subject =E2=80=9C(true)=E2=80=9D and = making matching =E2=80=9Ctrue condition=E2=80=9D by default. > So $var =3D match (true) { =E2=80=A6 } can be used as $var =3D match { = =E2=80=A6 }.=20 >=20 > It=E2=80=99s often used in Kotlin. Pretty convenient way to use = combined conditions. It=E2=80=99s natively understandable because there = should be a condition: >=20 > $result =3D match { > $x < $n =3D> =E2=80=A6, > $x > $n =3D> =E2=80=A6, > else =3D> =E2=80=A6, > } >=20 > The same explanation for switch construction, but in Kotlin it=E2=80=99s= the same construction =E2=80=9Cwhen": >=20 >=20 > val result =3D when { > x < n -> =E2=80=A6 > x > n -> =E2=80=A6 > else -> =E2=80=A6 > } >=20 > var result =3D null > when { > x < n -> { result =3D =E2=80=A6 } > x > n -> { result =3D =E2=80=A6 } > else -> return > } >=20 > = https://kotlinlang.org/docs/control-flow.html#when-expressions-and-stateme= nts`when` construction is overwhelming, but some features are totally = handy, such as checking for class of the subject: > when (obj) { > is Class1 -> =E2=80=A6 > is Class2 -> =E2=80=A6 > else -> ... > } >=20 > Which was implemented by Ilija Tovilo in: = https://github.com/php/php-src/compare/master...iluuu1994:pattern-matching= >=20 > By the way, what do you think about allowing to drop the subject of = match / switch as a first iteration? > Maybe would be better to ask Ilija to recreate his PR? >=20 >=20 > ---------- >=20 > Best regards, > Dmitrii Derepko. > @xepozz I would like to bring the discussion up and try to figure out all pros = and cons of this ability. Moreover, coming Pattern Matching is a great addition to have this = merged: $x =3D match { $a is =E2=80=9Cpattern=E2=80=9D -> =E2=80=A6 $b is =E2=80=9Cpattern=E2=80=9D -> =E2=80=A6 $c =3D=3D=3D null -> =E2=80=A6 $this->lastChance($d) -> =E2=80=A6 default -> ... } Again, it should work as it would have `(true)` context. So the = following snippet: var_dump(match(true) { 1=3D>'one', 0=3D>'zero', default=3D>'default', }); will produce =E2=80=9Cdefault=E2=80=9D, because =E2=80=9Ctrue=E2=80=9D = is not =E2=80=9C1=E2=80=9D and =E2=80=9C0=E2=80=9D. IDE may highlight such cases because they=E2=80=99ll never match so it = would be detected as dead code. ---------- Best regards, Dmitrii Derepko. @xepozz --Apple-Mail=_365812BE-518D-4A99-9162-430A7D0140C6 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Feb 2, 2025, at 4:04=E2=80=AFPM= , Dmitry Derepko <xepozzd@gmail.com> wrote:

Hi!

I=E2=80=99m thinking about = making match (true) and switch (true) be more lightweight by removing = the subject =E2=80=9C(true)=E2=80=9D and making matching =E2=80=9Ctrue = condition=E2=80=9D by default.
So $var =3D match (true) { =E2=80= =A6 } can be used as $var =3D match { =E2=80=A6 = }. 

It=E2=80=99s often used in Kotlin. = Pretty convenient way to use combined conditions. It=E2=80=99s natively = understandable because there should be a = condition:

$result =3D match {
  = $x < $n =3D> =E2=80=A6,
  $x > $n =3D> = =E2=80=A6,
  else =3D> =E2=80=A6,
}

The same explanation for switch construction, but in = Kotlin it=E2=80=99s the same construction = =E2=80=9Cwhen":


val = result =3D when {
  x < n -> =  =E2=80=A6
  x > n -> =E2=80=A6
 = else -> =E2=80=A6
}

var result =3D = null
when {
  x < n ->  { = result =3D =E2=80=A6 }
  x > n ->  { result =3D = =E2=80=A6 }
  else -> = return
}

`when` construction is = overwhelming, but some features are totally handy, such as checking for = class of the subject:
when (obj) {
  is Class1 = -> =E2=80=A6
  is Class2 -> =E2=80=A6
 = ; else -> ...
}


By the way, what do you think = about allowing to drop the subject of match / switch as a first = iteration?
Maybe would be better to ask Ilija to recreate his = PR?


------= ----

Best regards,
Dmitrii = Derepko.
@xepozz

I would like to bring the discussion up and try to figure out all = pros and cons of this ability.
Moreover, coming Pattern = Matching is a great addition to have this = merged:

$x =3D match {
  $a is = =E2=80=9Cpattern=E2=80=9D -> =E2=80=A6
  $b is = =E2=80=9Cpattern=E2=80=9D -> =E2=80=A6
  $c =3D=3D=3D = null -> =E2=80=A6
  $this->lastChance($d) -> = =E2=80=A6
  default -> = ...
}

Again, it should work as it = would have `(true)` context. So the following = snippet:

var_dump(match(true) = {
  1=3D>'one',
  = 0=3D>'zero',
  = default=3D>'default',
});

will = produce =E2=80=9Cdefault=E2=80=9D, because =E2=80=9Ctrue=E2=80=9D is not = =E2=80=9C1=E2=80=9D and =E2=80=9C0=E2=80=9D.

IDE = may highlight such cases because they=E2=80=99ll never match so it would = be detected as dead code.

----------

Best = regards,
Dmitrii Derepko.
@xepozz

= --Apple-Mail=_365812BE-518D-4A99-9162-430A7D0140C6--