php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49939 iconv_substr() misbehaves when length parameter set to 0
Submitted: 2009-10-21 08:32 UTC Modified: 2009-11-13 19:48 UTC
From: ladislav at marek dot su Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID: None
 [2009-10-21 08:32 UTC] ladislav at marek dot su
Description:
------------
According to documentation and reflection: iconv_substr has third argument $length, default value is 0, but iconv_substr returns different result when argument is not passed and when argument is passed as zero. (Now it's not possible to call iconv_substr with $charset argument and preserve correct behaviour.)

Reproduce code:
---------------
var_dump(iconv_substr('foobar', 3)); // "bar"
var_dump(iconv_substr('foobar', 3, 0)); // ""
var_dump(iconv_substr('foobar', 3, NULL, 'UTF-8')); // ""

Expected result:
----------------
string(3) "bar"
string(0) "bar"
string(0) "bar"

Actual result:
--------------
string(3) "bar"
string(0) ""
string(0) ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-21 10:24 UTC] jani@php.net
It's just a bug in the docs. iconv_substr() behaves exactly same way as substr() does with same parameters.


 [2009-11-13 19:48 UTC] svn@php.net
Automatic comment from SVN on behalf of vrana
Revision: http://svn.php.net/viewvc/?view=revision&revision=290687
Log: Length default (bug #49939)
 [2009-11-13 19:48 UTC] vrana@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.

Default is strlen($str).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 06 13:00:02 2025 UTC