Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51752 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5867 invoked from network); 30 Mar 2011 14:44:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Mar 2011 14:44:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=jbondc@openmv.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jbondc@openmv.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain openmv.com from 64.15.152.204 cause and error) X-PHP-List-Original-Sender: jbondc@openmv.com X-Host-Fingerprint: 64.15.152.204 mail.ca.gdesolutions.com Received: from [64.15.152.204] ([64.15.152.204:60907] helo=mail.ca.gdesolutions.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B4/94-07269-FA1439D4 for ; Wed, 30 Mar 2011 09:44:00 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.ca.gdesolutions.com (Postfix) with ESMTP id A884D5C4B; Wed, 30 Mar 2011 10:43:56 -0400 (EDT) X-Virus-Scanned: amavisd-new at gdesolutions.com Received: from mail.ca.gdesolutions.com ([127.0.0.1]) by localhost (mail.ca.gdesolutions.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id o6zN40sVzV7z; Wed, 30 Mar 2011 10:43:55 -0400 (EDT) Received: from djbondc (modemcable005.23-57-74.mc.videotron.ca [74.57.23.5]) by mail.ca.gdesolutions.com (Postfix) with ESMTPSA id 9AB3C5C25; Wed, 30 Mar 2011 10:43:55 -0400 (EDT) To: "'Hannes Landeholm'" , "'Dan Birken'" , References: <4D92CC38.5040900@toolpark.com> In-Reply-To: Date: Wed, 30 Mar 2011 10:43:54 -0400 Message-ID: <004301cbeee8$e54a8280$afdf8780$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Acvu20HWBhrrlK0XTiSQCkaFoXbTkQAATPzQ Content-Language: en-ca Subject: RE: [PHP-DEV] Adding a more logical string slicing function to PHP From: jbondc@openmv.com ("Jonathan Bond-Caron") On Wed Mar 30 09:05 AM, Hannes Landeholm wrote: > > var_dump(\substr("foo", 5, 6) == "", (string) false, false == ""); > > Welcome to PHP. To be honest this criticism pretty much falls in the > "from person that comes from another language X and is annoyed that > every little detail isn't exactly the same"-category. Just make your > own substr() function that uses the behavior you expect if you don't > like the native version. Although that's bad practice - the best > solution is to get used to it. And if you have an urge to write about > your experience with a new language I suggest you do it in a blog > instead of posting it in the internals mailing list... I agree with what you're saying but I think you're being a little harsh, experience with a new language should be something that matters to internals. Back to Dan, you're hitting type conversion so not sure I understand "you always have to deal with this FALSE case": var_dump(substr('', -1) == '0'); // TRUE var_dump(substr('', -1) === '0'); // FALSE Equally to Dan, it doesn't seem like a great way to start the conversation by saying the "interface is inconsistent and confusing". There's a perception issue here since you're already used to using language X,Y,Z. That said the patch seems to add value to php, why not add str_slice() if it can solve consistency issues for some users? str_slice likely could be a faster alternative to substr() in userland parsers. Also I've seen plenty of bugs caused by type conversion & substr() in userland