Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56322 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90682 invoked from network); 14 Nov 2011 06:27:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Nov 2011 06:27:10 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.210.170 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.210.170 mail-iy0-f170.google.com Received: from [209.85.210.170] ([209.85.210.170:53161] helo=mail-iy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 19/16-35419-DB4B0CE4 for ; Mon, 14 Nov 2011 01:27:10 -0500 Received: by iakc1 with SMTP id c1so8279653iak.29 for ; Sun, 13 Nov 2011 22:27:06 -0800 (PST) Received: by 10.42.147.65 with SMTP id m1mr21329456icv.27.1321252026586; Sun, 13 Nov 2011 22:27:06 -0800 (PST) Received: from [192.168.200.5] (c-50-131-44-225.hsd1.ca.comcast.net. [50.131.44.225]) by mx.google.com with ESMTPS id dd36sm28998058ibb.7.2011.11.13.22.27.04 (version=SSLv3 cipher=OTHER); Sun, 13 Nov 2011 22:27:05 -0800 (PST) Message-ID: <4EC0B4B7.4010900@lerdorf.com> Date: Sun, 13 Nov 2011 22:27:03 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: Pierre Joye CC: Antoine Delignat-Lavaud , internals@lists.php.net, =?ISO-8859-1?Q?Johannes_Schl=FCter?= References: <4EBF1F70.5090700@ens-cachan.fr> <1321150216.1766.6.camel@guybrush> <1321183356.2528.16.camel@guybrush> <4EBFD032.7050408@ens-cachan.fr> In-Reply-To: X-Enigmail-Version: 1.4a1pre Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [PATCH] Making in_array a language operator From: rasmus@lerdorf.com (Rasmus Lerdorf) On 11/13/2011 10:08 AM, Pierre Joye wrote: > 2011/11/13 Antoine Delignat-Lavaud : >> So this means being able to use $string->strlen() (or even $string->len()) >> instead of strlen($string) or $array->in_array($x) ($array->in($x)) instead >> of in_array($x,$array), right? > > Yes, that's the idea, but then with obvious names: > > $string->length(); or $string->length; > $array->in($x); > > instead of reusing the horrible string functions we have right now > (needle haystack orders and other (impossible to remember) funny > things ;). > >> That seems like a step in the right direction, with no change to the syntax >> required. I'll try to see if I can make an implementation of this but I fear >> it might be a bit more complex than just new language constructors. It could also easily be a step in the wrong direction if it isn't implemented carefully. Turning interchangeable scalar types into fake objects could introduce the equivalent of strong typing. Doing: $a=12; echo strlen($a); and getting 2 shouldn't suddenly break if you do it using $a->length() which means all scalar fake object methods would be available on all scalar objects regardless of their type. Otherwise it is just a sneaky way of introducing strict typing and that would cause a lot of pain for a lot of people. And while I know I floated the idea myself a while back, I'm not a fan of scalar objects at all. It's not like it cleans up the global namespace any, and given the requirement to maintain interchangeable basic scalar types it doesn't even provide clean per-scalar namespaces since all the methods would have to be in one. -Rasmus