Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126885 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 745801A00BC for ; Fri, 21 Mar 2025 10:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742551732; bh=BqMOpRukGRk0/IsmmcaZOa/aCGbk0jsAgxottWbFAwc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jGib38EPuPYZ7Hn4KsdNsJayemojFq3AtNTVCDrVXWH5UlYW3WsYr/SLfWC37mZPY HFLh0OyExvp3S5ZuP3rWkoVuC5Ayukx5VMBHoFfLbEB9M8qkdzFAH8OnB3WvBqDOnP IJ3KexvXNNMl8wLed2VSFgT3uM9Xf4zz5orKUXmgsi2SokAqVAQeE2hsB9IHR1d8mi +tGre6TO+vEY6cADl4XY3spop6qQSzNuR5e6kdvuEuhZGWnfTto0Fe+dI350Odza8F KipD7fwvvdvkEK9l4wfckcUH/MJXhpI1ijvbsjHlTp8KoRTQsbTcm6TsmW3OmxPT7A Dwqxe4QcP5kdA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1FC9318005B for ; Fri, 21 Mar 2025 10:08:52 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 ; Fri, 21 Mar 2025 10:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1742551881; bh=lSkszRHUvykOjNWWeNHJtYAgKrB1Q+mfpadE8JePQZA=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=JUK4qdQPzuTO2fksUpOP3WAQhSjtvFkzUfQkWWS+L2f1ayJ41ocDvrHu/eHT82Iyv OVdGbVAnjOOWjUwdTRh0pULSJ0Im02ibHoG23O4ut4XE7Jx7w2phbqRxmk9jVKYv/x GrpLmxt56vqosboV0eauuPhrPvcK6kB6HhzsMZPg7LXJNcYlzMn+5Urvi5aVOSFtyf RZAith+tj+xOlu6fQz2gtx2poYc4BYdjHNAGpPDdO5XzjUX9zAXg706/p/c2J3dyQq uCCm3RjRIu/BF5GtcaAsrjqrb/P0rOesZMNly7MV5n9vQx96q+J7tS9UYLw9Tq0rdc 6fYCK2aQR9AsQ== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Fri, 21 Mar 2025 11:11:20 +0100 To: "Gina P. Banyard" Cc: "Rowan Tommins [IMSoP]" , internals@lists.php.net Subject: Re: [PHP-DEV] Consensus on argument validation for built-in functions In-Reply-To: References: <041d1a8c-dd43-4592-b997-ad4d2f91aeac@app.fastmail.com> <95d08053-7500-4cc3-b84b-cb7cc837c065@rwec.co.uk> Message-ID: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-03-20 17:00, schrieb Gina P. Banyard: > And again, ValueErrors are only ever added when it *easy* to check if > the condition is satisfied, and it very clearly points to a programming > error. > > I still find it baffling that telling someone that the code they wrote, > even if it is decades old, is incorrect is somehow bad. > Because the alternative is letting users have bugs in their software > that they can ignore. I agree with that (and Kamil, who said the same thing). Passing an undocumented value that does *something* is a clear programmer error that would also break when adding new values, which is generally considered a backwards compatible change. Pointing out this error as an actual error before it causes a silent behavioral change is a good thing. The `round()` function would be a good example. PHP 8.4 both added a validation of the `$mode` parameter if an integer value is given and also added new rounding modes (just as an enum in the gold release, though). Before PHP 8.4 it was possible to use `round($value, 5)` by accident and it would be interpreted as `PHP_ROUND_HALF_UP`. Now if we would've added a new `const PHP_ROUND_WHATEVER = 5;` constant this code would silently have changed its behavior. As a user I certainly would be interested in finding out about this mistake. A clear ValueError is easy to fix in a backwards compatible way, but incorrectly rounded values can remain undetected for so long that it becomes impossible to fix them, since the stored data might already be poisoned, including all backups. Best regards Tim Düsterhus