Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5565 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90257 invoked by uid 1010); 19 Nov 2003 18:30:28 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 90223 invoked from network); 19 Nov 2003 18:30:27 -0000 Received: from unknown (HELO mail.zend.com) (192.117.235.230) by pb1.pair.com with SMTP; 19 Nov 2003 18:30:27 -0000 Received: (qmail 3878 invoked from network); 19 Nov 2003 18:30:25 -0000 Received: from guardian.zend.office (HELO andi-laptop.zend.com) (10.1.1.4) by int.zend.com with SMTP; 19 Nov 2003 18:30:25 -0000 Message-ID: <5.1.0.14.2.20031119202827.0465a100@127.0.0.1> X-Sender: andi@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Wed, 19 Nov 2003 20:30:25 +0200 To: Morten Poulsen ,internals@lists.php.net In-Reply-To: <1069249148.1962.52.camel@mopo.tv2i.dk> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] [PATCH] substr() returns false From: andi@zend.com (Andi Gutmans) References: <1069249148.1962.52.camel@mopo.tv2i.dk> Not sure if/how this should be changed. Isn't it a mistake to give a start position at the end or beyond the string? In this case, doesn't it make sense to return false? Andi At 02:39 PM 11/19/2003 +0100, Morten Poulsen wrote: >Hi, > >Even though this is documented, it is strange behaviour: If the from >parameter to substr() is at, or past, the end of the input string, the >function returns false. > >The function is documented as >string substr ( string string, int start [, int length]) > >IMHO substr() should either > >1) be changed to do like Perl, which returns an error only if start is >_beyond_ the end (not _at_): >(from http://www.perldoc.com/perl5.6/pod/func/substr.html) >my $null = substr $name, 6, 2; # returns '' (no warning) >my $oops = substr $name, 7; # returns undef, with warning > >2) be changed to return an empty string, if start is either at or beyond >the end of the input string. > >I have attached patches for both solutions. > >If you don't change it to be like Perl, I think it should be noted in >the documentation (as with chop()). >If, on the other hand, it _is_ changed to behave like Perl, I think it >should be emphasized that you are not guaranteed that the result is a >string, because this will cause (eg. has caused us) problems when using >the result as part of the $data array to PEAR DB::execute(). > >Happy hacking, >Morten > >-- >Morten Poulsen >http://www.afdelingp.dk/ > > >-- >PHP Internals - PHP Runtime Development Mailing List >To unsubscribe, visit: http://www.php.net/unsub.php