PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #49939 iconv_substr() misbehaves when length parameter set to 0
Submitted:21 Oct 8:32am UTC Modified: 13 Nov 7:48pm UTC
From:ladislav at marek dot su Assigned to:
Status:Closed Category:Documentation problem
Version:5.*, 6 OS:*
View/Vote Developer Edit Submission

[21 Oct 8:32am 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) ""
[21 Oct 10:24am UTC] jani@php.net
It's just a bug in the docs. iconv_substr() behaves exactly same way as
substr() does with same parameters.

[13 Nov 7:48pm 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)
[13 Nov 7:48pm 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).

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC