Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122442 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 887661ACEBF for ; Tue, 20 Feb 2024 13:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1708435338; bh=W5UJGI2Bk1S7RGT0VQxHT5MAZNQ5MC+vgLfSAB/SmZg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=KGIW0+fyoU5yCvDVW/FOJdPp/yEizsDoSnmSR2+fu2xS8Vk7DulrWJZPvxbXNovwA O4t8p9ByHn4zkiSM3h/SAPLuB5Pc1dGtkrQ5G+x9hA0mIx9XDo0jJTiEThju0Z0tZ7 andhziR0ZM2/RtfqnQswS/VZ+NEjylWzse+Us5O+BzticY+519QKdHtmUDMj0RwqnP 7njV0dis3auoflb/GcA0AulKKmIygZcbN5SoXvMQEEKEpGzvg8pd5WhzV3uJ0pcTAI c0MpckGgxRrJzDM+EOitt8MaSY8PXVB6xjjZn0yOuH6v7oj37Ae0pgNyONT6DAatQe Ub9bNAyhrZx+g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0C2581801DF for ; Tue, 20 Feb 2024 13:22:17 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, 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=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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, 20 Feb 2024 05:22:16 -0800 (PST) Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-599f5e71d85so3435732eaf.3 for ; Tue, 20 Feb 2024 05:22:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708435331; x=1709040131; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=W5UJGI2Bk1S7RGT0VQxHT5MAZNQ5MC+vgLfSAB/SmZg=; b=D/u6uhymO9MDl0gmkWTcAAa346UVqLRTz5RnJBG+DB0r4TNTJTRsNuWecF6SAKlTNJ z4vnCQzA7hXJIXqqpbz7HP6TQEnl0QjyqbngFNwChsZuWrYk6JoLKEIcSXxYoXzL7to6 JC3Aus+185ZAy9flpw56aVDG94whFt3f9U8AxE5VH4Pjb9Hv3y6C8xXWEWbV/wnIyywt /HwXEL0kkFVWdBdHKsQSJtf2zuuNIhaRpm2I8G7CZFajxbIhMPyuoo/99IQ/WvujSmFk yMZeuIzmCy5fY8R2lN5wYv5tYFrWjahAT32afSz0MODuCJ7YIWEFLPZ97uB+Cxvop01O doag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708435331; x=1709040131; h=content-transfer-encoding:cc: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=W5UJGI2Bk1S7RGT0VQxHT5MAZNQ5MC+vgLfSAB/SmZg=; b=TDUWDnnDUguqOAuPEL4zT32WdKHlDbWPlE4fwCVpgS8bMUcgM6vYlkc5IrW7EJEfgS iED93rnD2lt+Ncez1HviWGIsZgD9++Jy14y8FBSRBQmmc5FAYkL3OKdCMeMX6cxk8Zk6 JqZiJZFe0FnznxkbFUM+1qq78pYgawnLU3Y8MxELqmYwRhKVLN+04j0GnS9puOkrF/58 ak7syNDmnIdP2FTvhNmIp1i9lvvvhh0+Qf2Z0EwbXkOTel8F5h0in7A3naDuJmuS1NY5 MjBCavm1ZxFSxLDLwzCik7quIHgOUVpwLL1pJo+Z6NOIuf1O/LuuzAY4FqS+N8IjaZv1 uacw== X-Gm-Message-State: AOJu0YwjFdo6VJ+3G9ekCFDWuOdxZP8GgOzOVmShGYxsMQnz6U8/lcE5 OVkyvLhdZWGAPzEC8FPTsivCbihwf7Ch0UOtW8VWH5Q9BcUqfTvAV3losbzBF5kGqmY13Jwiy5H 5+oaZSv43R5VI7W5P4G57CrG5buU= X-Google-Smtp-Source: AGHT+IEp5v296yA3RaPeVDBgyOymSH2vCBWtHOdP1ZFMxY3m6Yu3EBv4tixCfoh2XikVr8EP3enGes7WU2M77IgG6ME= X-Received: by 2002:a4a:dfbb:0:b0:59f:fe70:3282 with SMTP id k27-20020a4adfbb000000b0059ffe703282mr1161360ook.7.1708435331500; Tue, 20 Feb 2024 05:22:11 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 20 Feb 2024 14:21:57 +0100 Message-ID: Subject: Re: [PHP-DEV] ArrayAccess and array_key_exists function To: =?UTF-8?Q?Ond=C5=99ej_Mirtes?= Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Mon, Feb 19, 2024 at 1:35=E2=80=AFPM Ond=C5=99ej Mirtes wrote: > > Hello everyone, > I was recently surprised that ArrayAccess does not work with array_key_ex= ists() function. > > I am aware that ArrayAccess objects cannot be made to work with many arra= y functions because it does not provide a way to iterate over its keys, you= can only ask for and set specific previously known keys. > > But it could be made to work with array_key_exists(), because it already = works with isset() and there=E2=80=99s a direct method that could be used f= or this - offsetExists(). > > The use case I have in mind is that sometimes libraries that originally u= se =E2=80=9Carray=E2=80=9D in return types want to switch to objects and th= ey make these objects to implement ArrayAccess, for maximising the backward= compatibility with the old version. This mostly works, except for array_ke= y_exists(). > > Do you think we could add support for ArrayAccess objects in the 2nd para= meter of array_key_exists() function? > > Thank you. > > Ond=C5=99ej Mirtes I'd love to see all array_* functions accept iterators/objects instead of only just arrays. Yes, I know the name says "array" but often we just mean "do this operation on this thing that looks enough like an array for now." Robert Landers Software Engineer Utrecht NL