Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127443 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 2E9DD1A00BC for ; Sat, 24 May 2025 15:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748102015; bh=C0djDEBPD7PeEMiyI7oC69Hs95PbUhZirmxvQdPnViQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VJ8YGbVFlUj0I13wfZKeZvgQdfKV04RNix+OjecjPtyq5gXeTS0q6vMocuoERaVlU Zvk3eUOnSkJs+eM/vhBBslLZv76uEBMueZXX27BaZtdPWMCe8bRza3yJESCLu2+po2 9Vu3mw+ioer7sqjeHZHGriboypHXUNaqeYLhETIj0f5bZCxwGQGWvudc30kKL2NPso DR2Zhs9Czn+IOVAkIB/eS+P6S0p/QI36Zo3vS2abciFpOxIcR2R+6kaTwCK4QCeScI N07/2yPt/YaqV3tENwIJCMPdKwZh/GjdrfzcClyUGLqoMzUM5HcIpXq3/m7EAYrrmb aKe12y7Wm9RMA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A95DA180086 for ; Sat, 24 May 2025 15:53:34 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 ; Sat, 24 May 2025 15:53:34 +0000 (UTC) Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-552206ac67aso401539e87.2 for ; Sat, 24 May 2025 08:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748102141; x=1748706941; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JjsiNSLqsYL2rZ4f+nVAI02Gj28kKVzIR1PCGsfDXps=; b=flAOfky/OISFieM1bNGaHAgYMqa4BC2bqL/DgnyMBGaCIDduzWbJrsNdRtWZwkVDJF S3sjhQtdwr5whrLi1PHpEKiatYor6ZbKJKHgJik/t8ubqNpJ1uo4/hHYXRoC5c17ixKX zFbrq0fhmSBI5tyX5+0AAa4mi4QfyU5yIrU6NyRU4niJRMjJvZaXFATmJpQmz6NufFOD 8BGYf8X9/XQa2CxiZ/G91EXU6qGrluamFKNWgrSjHVOQ40pjZSyqbWGiuzJ71j7cxOxV yeJvHtFhtS7wZ+bNupzLL53Yomioh9iwoqlphrW15KWrxBbHny07ETGAKPgauEAQI2DV q6bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748102141; x=1748706941; h=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=JjsiNSLqsYL2rZ4f+nVAI02Gj28kKVzIR1PCGsfDXps=; b=SUSGxqiFZ2mlbQr6YU62whrMZQClw8gvBXSzs6cioHtAmDS34aiotLSOUfUUhAqcwW SGbZm5tiNVKMhiJnNae6f9S0xfXueJXF6MkXrEtq2Vef0InRIG6/A/x4hGRhhxgINYR2 mYuZ8WI6MWdoOVv6UNcdu7jjivO13GRTqZbssZNSw2yi3f//j4p/I5aB1J9Z8NrBWpBh aoHXx59hbO5WBQOaTFys9yNRhHmrMK6wk+ZmnkKElf6646Tr7gVm3/0XOQvRqYQu0oFz NWRqjyeOmtyPqPM7FmwkAKVT1Ng1RfMBtJRMp0W92ivDPo3mEBGaXo6cI4/itL51VUhs b63w== X-Gm-Message-State: AOJu0YwO+tQEpeRJ8F3bMCWLhhfsishTA+vtVDg4RdIop+eSmfHE+kDY nmTV16tdcyLU6zofE/KfmDVR/IaezJx9eohGqIlVVljAAAM4XH+Ic22CJGoIf6ZsXf8nLUMR1HE ejWgxKPBc25f0pGHlFxSbWmAYDU1BcMk= X-Gm-Gg: ASbGnctDrm8zGu2xUjg74jpTpCkVuoQVnGEQuoph65S8Hf0Lr/+UkbONlvpqekwR2ux YRBeY+hyKTc+jg4i3l74LZlMA2tc8CiAdOrBZgCTUYTBeXMJbmmyCsTrV175qrERZiv+hpBlW1l 7eBjTtR/Zo/Lq4oZywNhNGp7MX6W3xYyvF X-Google-Smtp-Source: AGHT+IHIVJsB5c5S/4XiY2ZSwQfgZ5B/7yy1bULsrxYLSprmzrT7QP/6KLAXGgnl9KCyrfy1P+MuazL4rr7JYDzpcjg= X-Received: by 2002:a05:651c:1545:b0:30c:12b8:fb8a with SMTP id 38308e7fff4ca-3295b926273mr9021351fa.0.1748102140322; Sat, 24 May 2025 08:55:40 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 24 May 2025 16:55:31 +0100 X-Gm-Features: AX0GCFtAxn-vZL9rDD0llyyWDG8jJFFlXwD5oIv_HN19oD9JZOsUDcgbnBvJB5o Message-ID: Subject: Re: [PHP-DEV] [RFC] Add preserve_key_types to array_keys() to prevent unintended int conversion To: =?UTF-8?B?6ams5q2j5by6?= Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: tekiela246@gmail.com (Kamil Tekiela) As far as I know, this is how array keys are designed and changing array_keys wouldn't solve the problem. The key is converted to the appropriate type during creation. Array keys are defined as string|int and expecting the values to be either string or int is a programming error. Static analysis tools should catch that out. If a developer remembers to use preserve_key_types then they would also remember that the key can be string|int and would design the rest of the code accordingly. So it seems to me like this solution is not the right one. I sympathise with the problem and I would prefer that the array keys keep the type with which they were created. I have seen so many times when a developer did something like this: ``` $arr = ['123' => 'foo']; foreach ($arr as $key => $index) { echo htmlentities($key); } ``` Do I remember correctly that it was because of backwards compatibility issues that this could not be changed?