php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50983 default value for $length parameter of substr_compare() is incorrect in docs
Submitted: 2010-02-10 01:07 UTC Modified: 2010-02-11 11:18 UTC
From: guy dot paddock at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.12 OS: Debian Etch
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: guy dot paddock at gmail dot com
New email:
PHP Version: OS:

 

 [2010-02-10 01:07 UTC] guy dot paddock at gmail dot com
Description:
------------
The documentation for substr_compare() indicates that the default value for the $length parameter is the string length of the $main_str parameter, but this doesn't appear to be the case.

Reproduce code:
---------------
---
From manual page: function.substr-compare#Description
---
<?php
        $a = "abc123";
        $b = "abc";

        echo "Is the documentation correct? ";
        echo ((substr_compare($b, $a, 0) == (substr_compare($b, $a, 0, strlen($b)))) ? 'true' : 'false');
        echo "\n";
?>


Expected result:
----------------
Is the documentation correct? true

Actual result:
--------------
Is the documentation correct? false

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-10 10:58 UTC] rquadling@php.net
According to the source code at http://svn.php.net/viewvc/php/php-
src/trunk/ext/standard/string.c?view=markup#l7865, the default value can 
be expressed as ...

max(strlen($str), strlen($main_str) - $offset)



 [2010-02-11 11:18 UTC] rquadling@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2010-02-11 11:18 UTC] svn@php.net
Automatic comment from SVN on behalf of rquadling
Revision: http://svn.php.net/viewvc/?view=revision&revision=294881
Log: Removed inline <initializer> for the length parameter and described the default value in the Parameters section. Fix bug #50983
 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of rquadling
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=2a8a61e20a8e3b5c81bfe38e7ef722611792ec09
Log: Removed inline &lt;initializer&gt; for the length parameter and described the default value in the Parameters section. Fix bug #50983
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 02 22:00:02 2025 UTC