Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121658 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11299 invoked from network); 11 Nov 2023 19:04:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Nov 2023 19:04:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 46689180087 for ; Sat, 11 Nov 2023 11:04:24 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 11 Nov 2023 11:04:23 -0800 (PST) Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5875e24c749so1588305eaf.1 for ; Sat, 11 Nov 2023 11:04:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699729463; x=1700334263; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=YqMDHbpE2CubUDljAASfSfQEDi8I2KzS/nk02jMOMCY=; b=eBvKs5y9IVmu6ifUSAqdz45g99PfJFw/21YJRtjrNJRdA43cLoRNa4xE8kQKzd4nlk QsEf7j1Z4dueEtuVKzGrnOPO4FFqmSiz6AFQqRP1gYQtyMHnhPgWujXjMfMXh+/0KSJS Dgy9Nn+6oVZcZN38L1vnD5Mw85GgzwXbs5dGgbyOmtGulJF+GqOK4Hbk9tsNqw+5OCWc 1OinbH+mL7j0MBnY3zWDmN5oJolGoSw8uoPb88d3UvpOIfv60GEmIFWYM8XAcEfQtymi R8tP78Rkp29JurlMU5+ODIovo8SfdK+2+1cvV00W0lR1X1wq6WBrb7wzlVFDqGmxjfqr bxLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699729463; x=1700334263; h=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=YqMDHbpE2CubUDljAASfSfQEDi8I2KzS/nk02jMOMCY=; b=d1QpRLSSSo70V8zm7LP2oMwoKhpKe0wV1znsLgVXtauwxJnMd99snRyHjRGv5FtTh0 b3RV4Pp9JwiyPBipIab4/Jn78rGpFDxNg/sOcNKWB8B6tP5hiB1U9NvNgdQjdwmcQDua iH+70e7s2o2WWvzbyT+/S3qbYZaRlKKf8YH0rGtB4MZxQeWIdP2IvWXRXsdk4QAQ0xCQ ujexG2Zss8yALDWpMVDBBycJ4gVp4BMOOm00N1W/QEYMR2pzGyu+9AThFI/Pp8S9p2ea ADnRh/GhJa3UU+GZKi4sO7EHN1df6KZiTkwVaRnzDaORumZQf0vorLHa1FZgaBRMM78x ZPaA== X-Gm-Message-State: AOJu0YxwXgkupp8fmXI1h4rFe5kh7ny+hcZsFK0S7QerQHG2qA9UNbXM 3pe2rrVxib0fZBvNe8J0Gr3yNCFZ3rzX/qZjk1ntp2j/tR6wdQ== X-Google-Smtp-Source: AGHT+IE5U+21QbYZcbjvfTBQx5d6oM4E94krGS6HUodJ6J6dYspEz4qbNeH5ldjwT81Ui6H0Axpp/9+zFbD7ASLLz+Y= X-Received: by 2002:a4a:3859:0:b0:57b:3b48:6f11 with SMTP id o25-20020a4a3859000000b0057b3b486f11mr3516092oof.4.1699729462746; Sat, 11 Nov 2023 11:04:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 11 Nov 2023 19:04:11 +0000 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000d760a00609e51a8f" Subject: Re: [PHP-DEV] Array functions with strict comparison From: davidgebler@gmail.com (David Gebler) --000000000000d760a00609e51a8f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Nov 11, 2023 at 6:05=E2=80=AFPM Andreas Hennings wrote: > Hello internals, > I noticed that array functions like array_diff(), array_intersect() > etc use weak comparison. > > That's not quite correct. Using the example of array_diff, the comparison is a strict equality check on a string cast of the values. So array_diff([""], [false]) will indeed be empty but array_diff(["0"],[false]) will return ["0"]. Tbh any use case for whatever array function but with strict comparison is such an easy thing to implement in userland[1] I'm not bothered about supporting it in core. But that's just me. I don't generally like the idea of adding new array_* or str_* functions to the global namespace without very good cause. There is a precedent for it though, in terms of changes which have gone through in PHP 8, such as array_is_list or str_starts_with. [1] Example: function array_diff_strict(array $array1, array ...$arrays): array { $diff =3D []; foreach ($array1 as $value) { $found =3D false; foreach ($arrays as $array) { if (in_array($value, $array, true)) { $found =3D true; break; } } if (!$found) { $diff[] =3D $value; } } return $diff; } --000000000000d760a00609e51a8f--