php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80073 levenshtein(): new ValueError not documented
Submitted: 2020-09-07 09:38 UTC Modified: 2020-10-09 14:15 UTC
From: claude dot pache at gmail dot com Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 8.0.0 OS:
Private report: No CVE-ID: None
 [2020-09-07 09:38 UTC] claude dot pache at gmail dot com
Description:
------------
In the manual page:

https://www.php.net/manual/function.levenshtein.php

it is stated that levenshtein() returns -1 if one argument is too long, but it doesn’t say that an error is emitted.

Test script:
---------------
var_dump(levenshtein(str_repeat('X', 300), 'a'));

Expected result:
----------------
Per the manual page; dumps -1 without warning/error.

Actual result:
--------------
In PHP 7: Emits a Warning and dumps -1.

In PHP 8: Throws a ValueError.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-07 09:52 UTC] claude dot pache at gmail dot com
Moreover, the change of behaviour of levenshthein() between PHP 7 and PHP 8 (which is a BC break) is currently not documented in UPGRADING:

https://github.com/php/php-src/blob/php-8.0.0beta3/UPGRADING
 [2020-09-07 10:01 UTC] requinix@php.net
-Summary: levenshthein(): warning/error not documented +Summary: levenshtein(): new ValueError not documented -Status: Open +Status: Verified -PHP Version: Irrelevant +PHP Version: 8.0.0
 [2020-09-07 10:01 UTC] requinix@php.net
Changed during https://github.com/php/php-src/pull/5816
 [2020-10-06 15:10 UTC] nikic@php.net
I wonder if we can't just drop that error condition altogether. Why is there a limitation of 255 characters? My best guess is that it's supposed to protected against the quadratic time complexity of the algorithm. But then again, the similar_text() function which has much worse (cubic) complexity, does not come with such a limitation. This doesn't seem like something PHP should be enforcing.
 [2020-10-06 15:18 UTC] nikic@php.net
-Package: Documentation problem +Package: *General Issues -Assigned To: +Assigned To: nikic
 [2020-10-06 15:18 UTC] nikic@php.net
PR to drop the check: https://github.com/php/php-src/pull/6286
 [2020-10-09 14:15 UTC] nikic@php.net
-Status: Verified +Status: Closed
 [2020-10-09 14:15 UTC] nikic@php.net
The string length limitation and the accompanying ValueError are now gone...
 [2020-10-09 15:43 UTC] claude dot pache at gmail dot com
There is still a documentation issue, which was the original purpose of this bug report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC