Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116548 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72055 invoked from network); 1 Dec 2021 13:20:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Dec 2021 13:20:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0DE2F180507 for ; Wed, 1 Dec 2021 06:19:23 -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=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, PDS_OTHER_BAD_TLD,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS 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-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 1 Dec 2021 06:19:19 -0800 (PST) Received: by mail-yb1-f171.google.com with SMTP id f186so63805638ybg.2 for ; Wed, 01 Dec 2021 06:19:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cAlusjVHsiunAPUYjogWaLpyRDBVy+WMPOQ8QsgUe4s=; b=SoPzu3snceL9N+6QRNliuCTyB5k+Z8Eqv0072+Zl83H1pr21SULapLGdJ/qyAygvcG 40+WCoNTHC8FgRljQQM/bsPpT6YJkz+XiwamTi5mJFqbBm/2+ACv/a/f2rxCKfbv0n91 hzfYYwH2xeextGjsAt4A2NeTQCNojMsFDzPjWO4QNEp0wfTMbfHdC+a+J+BBnpkKwYbi mot8Azc+JiHV5dgeKOTepQi50XUjQTZZw+MZvtznjLmadIMLTCkMndzpuRy9QJwGYYTT 8lEgDAmnSao8HGYIHz1hXfm83rtVS7lT73x9uMZfyFnNByGgH4ORKZoHK/2OTIrca/NM dgkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cAlusjVHsiunAPUYjogWaLpyRDBVy+WMPOQ8QsgUe4s=; b=jT/PNUNL6wyDq6N7aISTnYgnyxczUMglkXZRxGGMWpHKoaaO4R0tbikUS0hVngSdFD 2ZWG2NaVHuzwn75GNwWuCN0LY8Nu14YSCProv2Np9L5IA/ICkXUc8EEVtmuOTV70oLTS 3elBWETZWimUNdl40qYoFOFO9cusaEuyIbvL0GROWk73SM2M08pNblHU3GnH4CuThMpO H3H8VF2DAhQ2VBRBW2qYFN9DMJqoUPrMMVVc5VeSmVbtkNHLTX1i/9wBfIiU8SlWyf2T uiFnqB/1hbmjOtbDG9fS1t2O906vkszz59rlkD+DxYlO/wwGbB0YwwEnyz9oXcgi7G9x exSQ== X-Gm-Message-State: AOAM531qpZUEiiMLw1XX9jYpVCwNYjvDTh25Qs7eZ1Qkxb5+3fU5xhzf mKpqb1lWLihK/6N2xyJljPF82E+8ieAcsz7ioEA= X-Google-Smtp-Source: ABdhPJy81brX9H7A8rYJ4o7rqI1Sc3sgGQglD1NG8A0rXp/IxiKVe6GhkLP9UZdbPSQK5RLEtLHut9ThfbVPFsHm7w0= X-Received: by 2002:a25:ab05:: with SMTP id u5mr7628885ybi.571.1638368358829; Wed, 01 Dec 2021 06:19:18 -0800 (PST) MIME-Version: 1.0 References: <087101d7e6bb$30f27d70$92d77850$@webkr.de> In-Reply-To: <087101d7e6bb$30f27d70$92d77850$@webkr.de> Date: Wed, 1 Dec 2021 14:19:07 +0000 Message-ID: To: =?UTF-8?B?QW5kcsOpIEjDpG5zZWw=?= Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000000a144d05d2165cbc" Subject: Re: [PHP-DEV] Array comparison works completely different than documented? From: george.banyard@gmail.com ("G. P. B.") --0000000000000a144d05d2165cbc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 1 Dec 2021 at 13:56, Andr=C3=A9 H=C3=A4nsel wrote: > The official documentation contains a conceptual description of array > comparison in > https://www.php.net/manual/en/language.operators.comparison.php#example-1= 13 > . > > Curiously the people who wrote the inofficial spec (I think the HHVM team > at > Facebook?) came to > pretty much the same result, described in > > https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#re= lat > ional-operators > > : > > > If both operands have array type, if the arrays have different numbers = of > elements, the one > > with the fewer is considered less-than the other one, regardless of the > keys and values in each, > > and the comparison ends. For arrays having the same numbers of elements= , > the keys from the left > > operand are considered one by one, if the next key in the left-hand > operand exists in the > > right-hand operand, the corresponding values are compared. If they are > unequal, the array > > containing the lesser value is considered less-than the other one, and > the > comparison ends; > > otherwise, the process is repeated with the next element. If the next k= ey > in the left-hand > > operand does not exist in the right-hand operand, the arrays cannot be > compared and FALSE is > > returned. If all the values are equal, then the arrays are considered > equal. > > In reality, array comparison works completely different, it is however > unclear to me how exactly > it does work: https://3v4l.org/630vG > > Do we know how this happened? > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > It seems the docs are not accurate in that it will not try to find the corresponding element in the second array. By rearranging the keys to be defined in the same order the docs seems to match the corresponding behaviour: https://3v4l.org/2ta2k The actual C code implementation of how the arrays are compared (after some symbol navigation) is the zend_hash_compare_impl() function. https://heap.space/xref/php-src/Zend/zend_hash.c?r=3Dd3f073e8#2919 Hope this helps. Best regards George P. Banyard --0000000000000a144d05d2165cbc--