Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51755 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53099 invoked from network); 30 Mar 2011 19:36:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Mar 2011 19:36:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=birken@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=birken@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: birken@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:45086] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E5/30-51004-956839D4 for ; Wed, 30 Mar 2011 14:36:58 -0500 Received: by vwl1 with SMTP id 1so1437031vwl.29 for ; Wed, 30 Mar 2011 12:36:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=mUv1Utt9IA5+7OObuUi0GCsvInEAe4aXonInfwx0iUg=; b=iiBXihMgrVXPjKciFcnIS/bma+WdrPbSEdDWu+gDFdfaR1W0Vkw+TlPmMD3OOg5dEb pOaabAxkm/1vkZhsZ8T+dQHlIErtEp77HlwotoU2Nu/t4IsGzriVCtE8mA9LO06EcRjz 9UOb0qwXEVCfgYRGvNgUh2RLatkUv8zcAUp0w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=bffVYN/RIqGQzEXBsmfMh0axe0OVJFd+uFI3PJeSIKkQH8VvmQMt8HkDp795psX2BG b6YFX7staF+d4UiWIHgM0ydZVxMy/lDx3H7TxBA5daNTrWxqytliEZqR51WG5g70Hzxu dhTFoC89EBSb2vzpXz6etraf3cM2zBOOoosw8= MIME-Version: 1.0 Received: by 10.52.180.9 with SMTP id dk9mr2127694vdc.134.1301513815224; Wed, 30 Mar 2011 12:36:55 -0700 (PDT) Received: by 10.52.157.200 with HTTP; Wed, 30 Mar 2011 12:36:55 -0700 (PDT) In-Reply-To: <004301cbeee8$e54a8280$afdf8780$@com> References: <4D92CC38.5040900@toolpark.com> <004301cbeee8$e54a8280$afdf8780$@com> Date: Wed, 30 Mar 2011 12:36:55 -0700 Message-ID: To: Jonathan Bond-Caron Cc: Hannes Landeholm , internals@lists.php.net Content-Type: multipart/alternative; boundary=bcaec5186a4ca070c3049fb84c54 Subject: Re: [PHP-DEV] Adding a more logical string slicing function to PHP From: birken@gmail.com (Dan Birken) --bcaec5186a4ca070c3049fb84c54 Content-Type: text/plain; charset=ISO-8859-1 The example I picked in my patch was a little contrived, however I do think it is a useful benefit for functions to work in ways people expect, even in edge cases. There are a lot of people out there who do not know the difference between == and ===, and I think the fact that str_slice() has one less potential bug to worry about is a tangible improvement. As for adding other string functions, I agree, I think there are a lot of them that would be great to add. starts_with & ends_with for sure. I just didn't want to write a really large patch for a whole host of functions before having the discussion about this one. I also don't mean to attack PHP. I think the interface for this function is heavily borrowed from C, and I think because PHP has different goals than C (ease of use being one of them), that improvements can be made from this perspective. I think from a functionality point of view for an expert user, the C function interfaces are great. -Dan On Wed, Mar 30, 2011 at 7:43 AM, Jonathan Bond-Caron wrote: > 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 > > > --bcaec5186a4ca070c3049fb84c54--