Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51793 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81013 invoked from network); 2 Apr 2011 12:44:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Apr 2011 12:44:47 -0000 Authentication-Results: pb1.pair.com header.from=pasthelod@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=pasthelod@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: pasthelod@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-bw0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:44465] helo=mail-bw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BF/30-13200-D3A179D4 for ; Sat, 02 Apr 2011 07:44:46 -0500 Received: by bwz18 with SMTP id 18so3222380bwz.29 for ; Sat, 02 Apr 2011 05:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=owyExfERQ+HCHvUJmvD5IACgL3fXtqi3OqBj0dyTQNI=; b=GtW5hnGmn7THnYSnVC/NQy1Z6CYrdI3kw4WBc9enJkA4p4Lc895lByRSAhwjyx9gBX 4xa40VzmcmYdGp7q0mvla/6zwWtMj6cbl+T4e8td5Xkrn5n5q8vQq58J1XggLgtgRfWB 1Vgigq69qsHdx2Z8Y5DZCSvPHF2pFKY0TolK4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=lQKPBFEDwE6IWqWKMYyesDzRSnwRj8xHwyHhtB54POG/BSTQV5S6xmGG/aCdAge93V Hu1S0orK6xpVGOHv4GJH2qbc6Hprh7VRf32lO9fC72eUnmqoJFSzosNi3bS+4SIsnUDk qct8F9mhgGLF6QY3loJFTgZVoQk7B/tgb66mQ= Received: by 10.204.85.8 with SMTP id m8mr971983bkl.139.1301748280587; Sat, 02 Apr 2011 05:44:40 -0700 (PDT) Received: from [192.168.1.100] (catv-80-98-239-153.catv.broadband.hu [80.98.239.153]) by mx.google.com with ESMTPS id v21sm1926554bkt.11.2011.04.02.05.44.38 (version=SSLv3 cipher=OTHER); Sat, 02 Apr 2011 05:44:39 -0700 (PDT) Message-ID: <4D971A32.6040106@gmail.com> Date: Sat, 02 Apr 2011 14:44:34 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16pre) Gecko/20110319 Lightning/1.0b2 Lanikai/3.1.10pre MIME-Version: 1.0 To: PHP Development References: <4D92CC38.5040900@toolpark.com> <004301cbeee8$e54a8280$afdf8780$@com> <4D9387BE.4030808@divbyzero.net> <4D94984D.8060700@lerdorf.com> <4D94A111.7050501@moonspot.net> <520FB834-2614-4873-AC3B-0B2594B18471@roshambo.org> <4D94A350.70201@lerdorf.com> <4D94C380.2070402@lerdorf.com> <7277ABA7-4B48-49FC-8974-512D4341CCC9@oettinger.dk> In-Reply-To: <7277ABA7-4B48-49FC-8974-512D4341CCC9@oettinger.dk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Adding a more logical string slicing function to PHP From: pasthelod@gmail.com (Pas) On 2011.04.02. 13:38, Jacob Oettinger wrote: > On Mar 31, 2011, at 21:10 , Rasmus Lerdorf wrote: > >> On 03/31/2011 10:58 AM, Martin Scotta wrote: >>> I think it's time to stop thinking in terms of "functions" and move >>> forward to "abstractions" >>> >>> $s1 = 'string'; >>> $s1->contains($s2); >>> >>> $s1->indexOf($s2) === strpos($s1, $s2); >>> >>> Why can't the strings be exposed as pseudo-objects ? users can choose to >>> use them as a regular strings or by calling methods on it. >> >> This is actually something I have been toying with a bit. Adding the >> ability to call methods on both strings and arrays. I still don't like >> the idea of making them real objects as the overhead and the amount of >> code that would need to be changed in the core and in every extension is >> daunting. Anybody out there have a patch along these lines? > > > Sounds interesting. A few thoughts: > > The new "methods" could be implemented as functions that accept the string or array as their first argument. Thereby allowing them to be called as functions too. > > If the new methods are functions. Maybe they should be defined in the \string and \array namespaces. This would allow a fresh start in naming string and array functions, and allow addressing argument ordering issues. It would of curse also open endless discussions on which functions to include and the naming of these. > > If the new string and array functions were defined in some namespaces. Would it be possible to allow extending the string and array "classes" by defining more functions in those namespaces in userland and/or extensions? > > Should the new string functions be multibyte character set aware? > > Should the above be generalized so that the -> operator can be used on any simple type, and if the called "method" exists as a function in the types namespace, it should be called. This would break the task into two parts. !) changing php to attempt calling functions in a certain namespace for each simple type. 2) Writing extensions that create functions for each type, string and/or array would be obvious starting points. If I'm not mistaken you're talking about something like the Extension Methods in C# ( http://msdn.microsoft.com/en-us/library/bb383977.aspx ) which, by the way, seems like a great idea. The other thing that comes to mind is Scala's implicits ( http://www.codecommit.com/blog/ruby/implicit-conversions-more-powerful-than-dynamic-typing ) It solves the same problem, while being really powerful, because of Scala's type system. The problem of conflicting implicits (or whatever it'll be called) of course should be left to the developer, much like aliasing for traits. -- Pas