Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127080 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 D9B781A00BC for ; Tue, 8 Apr 2025 22:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1744151053; bh=ddwtZV6x5QtuAPl0hzKObE2ltqLU/gHuYPNQearwhrI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Fm/l1sAbYinzBAZDPHUJoNBTnonZAFlCsmEXZzR5y+U7FdPG1O7p17VdKyXQ1zyh6 WBUsniejTVG0jJyg+t1HFqO5QLaMjEyCvUDPox9ppGG2bGEIvlf3D4byxXg3fNlYNH 7dOrsjzGLgESl3S2izgB+Y81CSoJrc44iejv+nk66Z1OAHaPbizUb/rtkTZ91PvZF8 bX80tXejz5KtHnJko4BFTvSNsDJLj5wDCjek1+mKY69Y83R9Z7H5DzF5V4JA3MwXUm qx3QG796meGZN3XYYxWQ1rqwVr3R91LE0KS6VUvqvlPVt9NobrhE/6OPsVpPYJH0xy 42X7m/MP+FPvQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3E1E5180387 for ; Tue, 8 Apr 2025 22:24:11 +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_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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, 8 Apr 2025 22:24:09 +0000 (UTC) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-43d0359b1fcso869835e9.0 for ; Tue, 08 Apr 2025 15:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744151193; x=1744755993; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=lhq5V+b6LRp43EbrPQhICdV32bYGqWi5dJYTiGULD08=; b=lFIjbujM70qKijUFYfrY+sIOF6gomSDiO+uFFEikg2BmDObxR5wi3vsFV41+yNsiLU nu8s+4fVRuknyMgrHsBvHLiHfPJVtfJyUD+/4A6pLNJN+kGESuId+hgM52617Cqr4MdU 36zpoohSTF68irf8nY+CO6NtzmyhtnBp3v0Y9O4bEBHq7Hbze8nGKc5YtoLKV1W1+bBW cWt09CdPCgJ9zRUkl5uZcOpl+tRjSzyPKQiYToMySpzETKd9t9Os+t2Pn5ixHO6tjuow Uh6P/msFAAMdn1JcNjOgmkB5uNdQdT937oZFNA8hJBmjFFB2cD5pu6XKiop01S+GpCtb ij6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744151193; x=1744755993; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lhq5V+b6LRp43EbrPQhICdV32bYGqWi5dJYTiGULD08=; b=fhPzcTHvq1FiGY+2HGSPoxQdpM11GAAEvk8HEZHHKKccadg8bvQ0uqTxoJ+FKVCQor fuY2qNeI4jlppNwHHOjppx4cz2LrhFBeSUkZ1h8P91uNZOdoUvMm283JX9ebZXz5F6IJ eyWhBi5i2AUNSLxACrNQt1PIkmiyeFRNUKW7IPk8B6BmfBaLQYmRRrEkcHELf6hB5JFA QaG2BwFSWgARo6lfKYM31G6pMI85k+5qehu4q1YjXOZ94JgXw5uBv6KzKWsFV3P/lLtI RD3wHv4Lxr3EAwhfnCrOmhQyabKzCRVtMdqnhQ1RF6tMSuBu1oLxeyhOb26yjwG4/s1p lXJQ== X-Gm-Message-State: AOJu0Yw9RVfnKpVTXgI063Tjwt1eZRTljlj8NGzpzQaOwlQNg8KQxz91 6u/n0gWJ8bmZDTR574bLLy6SOcd18vaMlbnt/j9ssf+ztztyt18VZufbxQ== X-Gm-Gg: ASbGncsg/VA5IKgD0PeGZOC2AXQbmEG0rye181S5T6m+Hl+40csOMU3KVPm6EQXOIaO t25m/KIhXQEX3sfEJ0yceR1zLYHOmPpPUM92cSKpDLoo51F+2foggihKkYlu0i9Dxpomh9werSk cHGTtBYp+nZ33MZQBZI4oj8RmFBSGdQNiPsIhJ9YhAvnK3i7x80BIEK1lIPgCAIF3hKR6erneom smbZWu1cCskQdbVEdfKfnkNXVzC+YoLzMqgdVtK116KrBEf+Oz1SQ9zMEl6pbR89v02aLH533u7 rxTZgHDmIjouthSsAIMzHykO+7K2EWxEthAVCfuFfl2bIEBlcDGgF23FlHmh89IUG3UCThVjWzc 8DdZlMVwy0WFIKD0bdEods35jdPYjZGxsyxMWe7bo6oWwebCKdQjVPRdzshTif2jMXKYbAWogXH TOFs7grpDZGSg= X-Google-Smtp-Source: AGHT+IG8Am3GIcSjWmQ48gW6DaeAlBBpEgvtFFSWhh4eanGln239ZQ+pgUQxMLCUK24RIzpmECmFnw== X-Received: by 2002:a05:600c:2151:b0:43b:bb72:1dce with SMTP id 5b1f17b1804b1-43f0e55ecc4mr37972325e9.5.1744151192637; Tue, 08 Apr 2025 15:26:32 -0700 (PDT) Received: from ?IPV6:2a02:1811:cd2f:3500:5063:77f7:737f:ef82? (ptr-du5vm7cygtdqj8kc03m.18120a2.ip6.access.telenet.be. [2a02:1811:cd2f:3500:5063:77f7:737f:ef82]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43f205ecb8dsm1760425e9.7.2025.04.08.15.26.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Apr 2025 15:26:32 -0700 (PDT) Message-ID: <0f9bf0ec-6bf4-4ee2-8683-b774085136f5@gmail.com> Date: Wed, 9 Apr 2025 00:26:31 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last() To: PHP internals References: <51fcec92-b2ae-482e-920f-c6c991b526c5@gmail.com> <62C3AAC4-0D41-470B-AB26-8FC92B59E0EF@gmail.com> Content-Language: en-US In-Reply-To: <62C3AAC4-0D41-470B-AB26-8FC92B59E0EF@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: dossche.niels@gmail.com (Niels Dossche) On 4/8/25 8:46 PM, Claude Pache wrote: > Hi, > > I think that this argument is not convincing, and even counterproductive: > > * NULL is a rare legitimate value, so the potential for clashing is low > > First, it says that it is a “rare” legitimate value, which one can disagree with. (I do disagree.) > I think it's a matter of phrasing, but I agree that it can be more nuanced. > Second, the way it is formulated, it implies that, when `null` is used in array, there will be “clashing”, which is not necessarily the case. (I consider that there is almost never a clash, because it is rarely useful to make the difference between an explicit `null` and a missing value, and, when it is useful, you have almost surely already checked for an empty array upfront.) > > I suggest to replace that argument with the two following ones, that doesn’t treat arrays with NULL as second class citizens: > > * Semantically, NULL represents a missing value. Returning NULL from an empty array is not semantically incorrect, but it means that the function doesn’t differentiate between a implicit missing value (empty array) and an explicit missing value (array with NULL as its first/last element). > > * In the relatively rare cases you do want to make the difference between an empty array and an array that starts/ends with NULL, you can (and should) just check for empty array upfront. > That's indeed a bit better worded and more nuanced. I might adapt the RFC text a bit; although in the end it kinda means the same thing anyway. > ------- > > One more thing. On https://www.php.net/, I read: “Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.” (emphasis added). If we were to design some new perfect language, we might consider making `array_first()` (or equivalent) choke on empty arrays. But given the current state of the affairs, the pragmatic thing to do is to pave the cowpath. I agree. I value consistency; we have too much inconsistency already in PHP anyway, let's not add more (unless we would have a very very good reason to do so; but that's not in this case IMO).