Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126096 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 10F331A00BD for ; Mon, 2 Dec 2024 16:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1733156794; bh=DS5PvR2bATLxuL5Wfv5y0NZKvWcqITQ2jXJUOFo9mok=; h=References:In-Reply-To:From:Date:Subject:To:From; b=S4ivYJsYvnloUkSkhR+VGmMeENQhn870vM2y/KI090AuqyT0itExPEFY9YMSOf5p/ ORLyOIDgJkrsyBPghf8sSsdX2C5vYsYVo9jhpGUGzhXGqKFYM8bBMl451+N+WaI8ui IYIFcRa5qMWEUqSw1aIdPhcpj+kC+N/lts7tR9ZiR4mYIv4ErUDoEf4QoIHDlL2seS sBQVU3Fo0Wkglcfnl1y8G9cwGbqnUn4OO++2ud7oq+biqqT5Mbn8BABOkj3b/XvmgL rvr+JKP1cmoqC035QvilIkkTuIn16GL9xYvTz9lHXcPIXslWDGbC4ehFDGqUm0WvNC rnYYPGD9RQtgA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6AD08180071 for ; Mon, 2 Dec 2024 16:26:33 +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-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (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 ; Mon, 2 Dec 2024 16:26:32 +0000 (UTC) Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-6d8a3e99e32so9197306d6.2 for ; Mon, 02 Dec 2024 08:29:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733156980; x=1733761780; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UEpHYvkrHEDBO9mDh+PQec9jMeVM1K/DLCkbhvr1SJM=; b=doI9TEd8rAJoLCXKF4DrEBzBJSVLVH/lldZDoAGJ8Jj01Zz22EpzDMQwvpNHUP+N5A +KYJBd/nQuh3QZsT+hWhxZQTOe5nCJMo+fuXgyE3Q6ftNyPC0SqMRblE/HhfnSvmNh+O ALBSX86bDHRc1j9id5J8VbdieZsx8HlcPeH3CBs4rIg3O54U9uoJQJrLlVFLJPnvAczz JoLogLgeL2CpMUqWTAp8fI+wSVK8H+S94R14XnOZ1h7fji5dwtd84cuRwP80H2g45lUb fleWBsBbrAm2/LaxzkIqVF/AUEzITUbzHjcnrA4LSftdj/GnI6X1O25ZTQ/JJYzMdFPi CHUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733156980; x=1733761780; h=content-transfer-encoding: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=UEpHYvkrHEDBO9mDh+PQec9jMeVM1K/DLCkbhvr1SJM=; b=Zd9SJieaU3RT2PRbcQ5PcvUPArmDJj3VjTCZ9JWG8B4D1GzxuJVcTffIsJgQG6jaHt 5SCvOa8prPMsyzJzjP245MIa+O4vCfeATrq38K4j2qH9QDc878CCRHHP2TWlrKQPGi6u ewyZ+4QPD0fhiduq7X/pf+JGeXF50ERCnFXjajdh0zdn0hb03K3WiXBlaZdCXrShzWTk lpzF6drosRUM44rsmEb25lFgsGWSsZ26kQ1AaAVINH9ve7IDH2gqyEjEJVPcj1zo1PEw tdxCY8tZjlbUIUOzSGSFp2HhgzWwOBEznOn2oNlzbpKK8YxHx6ypBFFYSTP+xKjdYDbR xhmg== X-Gm-Message-State: AOJu0YyKwYz7jrHCjpXTXsGJdCnQufBgp7FxXJCBNqef6De0kHXgO9ZZ igoWWRz3ixURKfwkpQDK8377mcSOMDz6xr7OhbC5MfR/WwxyS0tSS+RGVkudWqbcC/zGvIq8psY Sm59crETJnzokZFu7KVdro0EnQRnu3qq7IV0= X-Gm-Gg: ASbGncthM5qh/DZqoIqMRp56yoY1ywLQYNR/SKI9bnZN+6QXnALWGtWpFxxTGTxRLpB eRFeRUsFx2l1doUSELR+izJYuh/nezPr8homHZEc119lki6TpxXUE8w3rEfTdNK0= X-Google-Smtp-Source: AGHT+IGzlWLlP3l0WDfSwBMj6+ag1e9OW2oLQVjkFWVby0rq5sbk0QLnitgn/Fu5MuF9jzqtMfoik+CSlrBVdjo71tA= X-Received: by 2002:a05:6214:20c5:b0:6d8:a610:21cc with SMTP id 6a1803df08f44-6d8a610256dmr101080346d6.1.1733156980201; Mon, 02 Dec 2024 08:29:40 -0800 (PST) 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: Mon, 2 Dec 2024 17:29:29 +0100 Message-ID: Subject: Re: [PHP-DEV] Re: Inaccurate documentation on return values from native functions To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) On Mon, Dec 2, 2024 at 1:31=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > On 01/12/2024 03:41, mickmackusa wrote: > > I can appreciate that. Going forward, is there any benefit to preserving= the behavior of returning integers beyond -1, 0, and 1? > Should these topically related functions receive a new last argument? boo= l $distance =3D false > > The functions are not attempting to return a meaningful "distance", this = is just an optimisation: the intended use case is as a callback to function= s like usort() which only care about <0, 0, >0, so no CPU time is spent nor= malising the result to specific values. > > The documentation is simply mistaken in saying "-1" instead of "a value l= ess than zero" and "1" instead of "a value more than zero". This is exactly it. This was already fixed in the upgrading guide a while a= go: https://github.com/php/doc-en/pull/3450 > The strcmp, ... functions, using binary safe string comparison is no long= er > guaranteed to return strlen($string1) - strlen($string2) when string leng= ths are > not equal, but may now return -1 or 1 instead. Instead of depending on an= y > concrete value, the return value should be compared to 0. The reason for this change is not to unify the output, but rather to avoid a bug on platforms where sizeof(size_t) > sizeof(int). When the length of the string exceeds what int can hold, the difference in string sizes can potentially not be represented by int. The data truncation may potentially lead to incorrect results. See this comment for details: https://github.com/php/php-src/pull/8220#issuecomment-1073337678 Ilija