Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87256 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35263 invoked from network); 23 Jul 2015 23:59:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jul 2015 23:59:32 -0000 Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.19 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.19 mout.gmx.net Received: from [212.227.15.19] ([212.227.15.19:52187] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F0/D2-13746-2EF71B55 for ; Thu, 23 Jul 2015 19:59:31 -0400 Received: from [192.168.0.100] ([95.89.139.132]) by mail.gmx.com (mrgmx001) with ESMTPSA (Nemesis) id 0MWCgz-1ZOcRm0DU1-00XL5V; Fri, 24 Jul 2015 01:59:23 +0200 Message-ID: <55B17FE2.5090208@gmx.de> Date: Fri, 24 Jul 2015 01:59:30 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: francois@php.net, internals@lists.php.net References: <001201d0c574$e1b63f80$a522be80$@php.net> In-Reply-To: <001201d0c574$e1b63f80$a522be80$@php.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:JWxtwlAF3zVB81hnocvZYKKVM6tSdbdWymFMWdoOFIllsJl306x /kJMRmFLY/hW8BTCIbgUIZAb38aJ2sHeJHa2oyG1ihH16iU7jCw5yL3UU6cgyTmnlZHp64q GQ63baveUc9FJRypzGiBCiHyGmZEjFaMisf/6Joz7S/MUJjK94JXZZY/1+JP9gdWPpYD3iI cPDaZkTPRwOa+deudAARA== X-UI-Out-Filterresults: notjunk:1;V01:K0:1EIVSXIV01o=:ppv6xLrhDXHKSod5kLiKxG gJIhS34aev8OXhURbtvIibHKsXvPorhpGASw6S+Vj1QXjXWeZtMFic6g5ejOP2GQEVdReE6sn Pxb3wl8sQJ6tY0lI4ANDVSfcxPjYoThjJY2MzH9ibCx1hMQHJoL8x0B/Ln8QOc8iwNAjtdpFU OwtjMzNdqgZ/s4AAteSHd0nMzDbJU6IngZdJLYxshYevyl9KVhe2QfY2+r6LFxiNFAs2XjSfL +LQ7LWDUSMFyzYw3uADdjNICPzjzCjisZxConNZlJ1e2Cf2Guq9I92qRxxCJ6HUOQeJJwx7am 1WvOOzf/zO6sOC4EExxN+HC2jl0ot1bCvEugoIDxtTEF/RTOAknED1ZEwbCaHJniYV+se5mvK RorETtO5yccAlINAV5n+AbnuNeDssXoh+DLrpoK41jvZq54ftXOJkJmRjQwfluHCqpjPqPJDM 9fdHKeZDfkFme+NTu1iZ28wCgKfi7cM7jgoLR0czfl+dMMtyGSEl+zb97hD/N8ff8f6/Zef+J e0KMf92o65oaqxJERy8sMNU5FIYLW4Kx4tx5V21Dn91T58jH9kibL4XIahEvpmER6SUOLngsd 6VHuSP72rdrhhDPMFPIe4pJ3CjMBzGrc24edu9e6kjvBJeIuIKryCKRIEd90xZ1KwulZ2DbKS QQ6ESGW31sKZotFS045Rot3RfHGGByTdqu+Lap+NFuBfDnp1sTo5DRV3ZkjPB8ftL6iQ= Subject: Re: [Proposal] Extend support for negative string offsets From: cmbecker69@gmx.de (Christoph Becker) François Laupretre wrote: > I need your thoughts on a PR (https://github.com/php/php-src/pull/1431) I am > working on. The subject is to change the way negative string offsets (and > lengths, where applicable) are handled, to make the behavior consistent with > the way they're handled in substr() and substr_replace(). If your return is > positive, I'll write the corresponding RFC. > > Implemented so far : > > - Support negative string offsets in read mode. Example: $a = $string{-2}; > > - Support negative string offsets in assignment mode. Example: $string{-2} = > 'z'; Generally, I like the idea of being able to specify negative string offsets. However, I'm usually working with UTF-8 strings, and as such I'm using string offsets rather seldom. > - strpos() : Accept negative values for the '$offset' argument > > - stripos() : Accept negative values for the '$offset' argument > > - substr_count(): Accept negative values for the '$offset' and '$length' > parameters (same behavior as in substr()). That may be useful as well, but what about the respective mbstring and grapheme functions? At least these should be improved as well, but I'm not sure if that can be done in an efficient manner. > I also have some questions : > > - Should we keep returning NULL on parameter parsing failure, while > documentation only states that false is returned on failure ? It is documented[1] that: | If the parameters given to a function are not what it expects, such | as passing an array where a string is expected, the return value of | the function is undefined. In this case it will likely return NULL | but this is just a convention, and cannot be relied upon. IMHO it's best to stick with the current behavior, and to consider to raise exceptions sometime in the future. [1] -- Christoph M. Becker