Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121513 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24525 invoked from network); 29 Oct 2023 20:02:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Oct 2023 20:02:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 383D61804BC for ; Sun, 29 Oct 2023 13:02:08 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FREEMAIL_REPLY,HTML_MESSAGE,HTTPS_HTTP_MISMATCH,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.80.0.0/12 X-Spam-Virus: No X-Envelope-From: Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02olkn2046.outbound.protection.outlook.com [40.92.43.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 29 Oct 2023 13:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VO/wergtt0ySEjoHJN6P4uo2JXFp1YblbjqRxsY7psLkOx2SO3J0/yIuaOrksM4U80d1IRBAoQ/sfCGw1OgoJ1QG+RkXczYa6AQmK6bYlBozfUH2JEJj51iIhrcziB/54F9BqfCR1bcz2rbYf+cjdeu3EZBizSk0UpREaz2vJJajgvnHFoFn2GrMO77Y+6j3RDpTxHk++k1KwrcUONdAa4UhxSgTp6r1ADJI6/a8tPaUULWI8zLaC1vOD+ibTF0kGIaAGiWoJry8H5KTkQYh0K4dHNj2SKCxavTaTZz3k1qIFyc1f+uKwwEKGNYQDM1uAFvxtXk8h5joXBTW7cgGBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=izuDmKFbe5eJ1ZH4zanq8HeLoClNGoOn95E7tg64jlA=; b=XTTpQenVOrqU3iucm64/gwlhxFM8Hb5s89p4jWH0N2P5ogQe0nbCokXrolXbwpXy+uiH/qwsio+50HQxTtTokc1fuC6xs0jx6JcRHu3YViB59zEt0kwdzkcEn3Bu2wn9Qay+mR0lt1iuVNfug1toV3Ja7yDGfqx2yTluLGDykgKX0ZaFmYFhhGLcPqHGJdB8pxEw9rHPGbzR8nwlwEo0X+lCTafKSWli150mInqWIDlnUy75K/ee7BvKCAG7SceucONil92zIqYXB1dZ73hFOmd+SeN8Tw8v8jQf5Gf078IqJVj85vOs4IdXxRrGcLAHc+yJF4oh9iYIBQhoCHMlyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from RO2P152MB6822.LAMP152.PROD.OUTLOOK.COM (2603:10d6:10:ed::11) by CPUP152MB5697.LAMP152.PROD.OUTLOOK.COM (2603:10d6:103:1c2::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.27; Sun, 29 Oct 2023 20:02:04 +0000 Received: from RO2P152MB6822.LAMP152.PROD.OUTLOOK.COM ([fe80::6535:892c:97be:f9d5]) by RO2P152MB6822.LAMP152.PROD.OUTLOOK.COM ([fe80::6535:892c:97be:f9d5%3]) with mapi id 15.20.6933.026; Sun, 29 Oct 2023 20:02:03 +0000 To: Sergii Shymko , Robert Landers CC: internals Thread-Topic: [PHP-DEV] Discussion - Anti-null coercion Thread-Index: AQHaCpYju+K3lo7yU0qzfKs0g2APD7BhLewAgAACOZQ= Date: Sun, 29 Oct 2023 20:02:03 +0000 Message-ID: References: <0CDEE8D1-7905-44B4-9C00-0251B94222C4@shymko.net> In-Reply-To: <0CDEE8D1-7905-44B4-9C00-0251B94222C4@shymko.net> Accept-Language: pt-BR, en-US Content-Language: pt-BR X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [RhQg3nHF3EX5SvEg0XKy+T+eW3275IVY] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: RO2P152MB6822:EE_|CPUP152MB5697:EE_ x-ms-office365-filtering-correlation-id: 5a8b4c9a-b530-43f7-2a22-08dbd8b9eb91 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: SKTL9qzzyKPYFUugpP9P/BKD80K0HrTKGLNRo/mudE4ZWfEgGNU/b+C8UCGgWI6Yjz/KE0pfmrEExU/7lINqj1MMslf15iA7eK0tbXIqe3vvpXT5eW3aDQSA3WppKE1IzwfM87yHHNnjj6IoviInrUtJ1DUDq7iKXT1gVJrL4jxewbNUjMBfRyQCNP87dfBPjEbKeGJHHaLFiEj5a3rHSYBfEkQ1jDfuBw/c5OZZXMMH1aMhOImvie33oFqVarEO1zkI0JU6HtRVNDy1TdqSkumOkGEuMU5WaN2H5W6ihdio+uD53QuXohO8jmgsXXTrw5Tt9zuPbV0uunOa9LkRDa7tM/9ylRkGa7lMleP8vy7bgTjsO9JSModT0HLnGa60cDxHVY4TJpu5koQ7a8x3Cm5Iqk7iHCgDSSGME9ivjJZ51vCaJ2IlnSYHAgDsklSnwGdXLpF3JrtHYj7p5bRUDZ1yuBB3kBbJW+GrpMUFzInRqc1kDKMA5Siep6rz+oEeEJXkokpx2dbJGOvPo3BbLnDBZ1PkYbIkgxEklvNoFV98OSZ/M8QjhyTr7dpqvJB0dRT8tNkjAS2s5Uj/jtPw4jLBblBoXI7gX7gugWcN5K4= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?Windows-1252?Q?VyXj4EEEgTAKpNx5IkchrzyfmY10jPO72dIfjCE4RjcoIc1G/pjmn9yk?= =?Windows-1252?Q?8oj6HAb/AFmjwj3jxlweZ2Mf6vdf2YIhXnG33BX3UeV2bBWrMJfn3ENd?= =?Windows-1252?Q?4bntScrKZrgfonLhS4GKZFu9IwTHLdq0PdfU2vv43E4gL1j66wusB54u?= =?Windows-1252?Q?5q4c5sfLT4vpCJK1M0YOp0GS44ckgkZR7+CuuhIae1T1t/G4nik+CkNM?= =?Windows-1252?Q?h4PrfIjetFufDzmUFkE7ZEYzjpByKtzIckzMGJ89fko8/b8agHC7ocfr?= =?Windows-1252?Q?QyXfqits0+Hbetclk/bh/Fd3IQvdnCc5WgRzlJuhuFoR6VfoG+ca0Mhh?= =?Windows-1252?Q?Pk89UzCWT/R0q9P4DycxvIrPcJXOXkiodvkbFy3GzHys4+PMYohzRV/G?= =?Windows-1252?Q?IwXastKgDEvkgZbMRLhqDn8hYToAlinV7mw2lOlcgrVL3I5qlBmpGus8?= =?Windows-1252?Q?5dpPXvZIcDCRsBky4ldg01K7DmrmcGKx0C4Bjcl1RRGBRx8MyeMU2HZT?= =?Windows-1252?Q?CiiEBtl/DjRJ4xTPIimN5oOmK0eN7+y1Ni7YJvuphCpiJzCBzI0QTxpi?= =?Windows-1252?Q?HPZYcejORML8PTLodLGP5Ppshpwe/Ea16FAgnV3+/HmTT6yx1apQygVT?= =?Windows-1252?Q?mdgZpjeqzQD9Kw6CW9ij7dAaGHlwTr2Q/P7MvSDpbp4ar7t6BJogx0M5?= =?Windows-1252?Q?j0hB0uLpbeXPdxUtNCqKolYViiLvIL5fW4ghh2nbdbxsOIEb4ifE0Psf?= =?Windows-1252?Q?E1WhAWUvzCpqItPkYz9Qv51ShqYuEl37IfuLIJ9lU1ryFueCBHYV/Qj8?= =?Windows-1252?Q?pg+m+LMpfij9PYb8GWFtwASuMawmRD9UFz78G/JH8FpUoC+W1aJ2fl39?= =?Windows-1252?Q?/MtNE2ZUQTpPiFDtd09XzgR3VhyRfXjiN9Frbvncf6A/ZbdNa2YAXpC1?= =?Windows-1252?Q?6duGeSOyguKt6lYRDnSUYJCCWkjpylatQWi56Qxpata/3SjijJCPcyCe?= =?Windows-1252?Q?jUMjqwc4wu8xlgk/7HE/Cc1xXVvOOhho41W9UPBeisNxHqsb9vZzeM5u?= =?Windows-1252?Q?Vb4qfpRxGq/8NxmJNJVh1Mpuyw8izrlaVPW4uxGtS3yuOqqd+7+JgDso?= =?Windows-1252?Q?Eq+6dQYqtsws+S+KDHDdpRo4OK60BWbftcGWLzvO7u4R8OX3pWc3qHCn?= =?Windows-1252?Q?dqRr0qL6Cv6KHxjkVpUMsd8/wh88GPlHseYH36QIvCmR/RyUhJOF89Uc?= =?Windows-1252?Q?TZQL7k4sh4F085eb7sG+JN6pOjEspjJaS64FxP/7VavRyBpZu+RDR7A6?= =?Windows-1252?Q?dxkGVLD/BxYMJ/rOP84K1MKUlsmbQkNigHTP7QCRzGk1hKDa?= Content-Type: multipart/alternative; boundary="_000_RO2P152MB6822CDA3A7C33702F4C632C4FBA2ARO2P152MB6822LAMP_" MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-bf824.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: RO2P152MB6822.LAMP152.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 5a8b4c9a-b530-43f7-2a22-08dbd8b9eb91 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Oct 2023 20:02:03.5160 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CPUP152MB5697 Subject: Re: [PHP-DEV] Discussion - Anti-null coercion From: fabiocarpi@hotmail.com.br (Fabio Carpi) --_000_RO2P152MB6822CDA3A7C33702F4C632C4FBA2ARO2P152MB6822LAMP_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Following the php logic, maybe !?? ________________________________ From: Sergii Shymko Sent: Sunday, October 29, 2023 4:53:12 PM To: Robert Landers Cc: internals Subject: Re: [PHP-DEV] Discussion - Anti-null coercion On Oct 29, 2023, at 1:31 PM, Robert Landers > wrote: Hello Internals, We currently have a null coercion operator: ??, but we lack an anti-null coercion operator. For example, if I wanted to operate on a header, if-and-only-if it exists, I'd have to write something like this one-liner: fn() =3D> ($_SERVER['HTTP_X_MY_HEADER'] ?? null) ? md5($_SERVER['HTTP_X_MY_HEADER']) : null; Or something like this: function() { if(!empty($_SERVER['HTTP_X_MY_HEADER']) { return md5($_SERVER['HTTP_X_MY_HEADER']); } return null; } This is rather tedious when you have to do it, so, I'd like to discuss adding a new "anti-null coercion" operator: ?! This would collapse the previous verbose code into: fn() =3D> $_SERVER['HTTP_X_MY_HEADER'] ?! md5($_SERVER['HTTP_X_MY_HEADER']; When it is null, it will stay null, thus the above is the same as: fn() =3D> $_SERVER['HTTP_X_MY_HEADER'] ?! md5($_SERVER['HTTP_X_MY_HEADER'] ?? null; It would have a lower precedence than ?? so that the above line would read from left to right without requiring parenthesis/brackets. The operator would only return the right-hand side if the left-hand side exists (aka, not null), otherwise, it would return null. I'm not particularly attached to the ?! syntax (since it does, in fact, look very similar to ?:), so perhaps focusing on the merits of the idea first, then bikeshedding the syntax later would be a good approach? Thoughts? Robert Landers Software Engineer Utrecht NL -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://na01.safelinks.protection.outlook.com/?url= =3Dhttps%3A%2F%2Fwww.php.net%2Funsub.php&data=3D05%7C01%7C%7Cf2f8309c674c4f= 9137a008dbd8b8b73a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C63834206009= 9962597%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI= 6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=3DFrc%2BghvwIS1q%2B79n4joMssX= CfeFIHkf7mziuH28XLW0%3D&reserved=3D0 Hi Robert, Why don=92t you combine the two examples and use a regular ternary operator= along with isset/empty()? fn() =3D> !empty($_SERVER[=91HTTP_X_MY_HEADER=92]) ? md5($_SERVER[=91HTTP_X_MY_HEADER=92]) : null; It=92s only ever so slightly longer than the proposed ?! operator, but way = more powerful. You explicitly control the evaluation expression along with = the default value. Regards, Sergii --_000_RO2P152MB6822CDA3A7C33702F4C632C4FBA2ARO2P152MB6822LAMP_--