Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61517 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92179 invoked from network); 19 Jul 2012 20:52:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 20:52:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.213.42 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.213.42 mail-yw0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:37401] helo=mail-yw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/17-18983-E9378005 for ; Thu, 19 Jul 2012 16:52:46 -0400 Received: by yhoo21 with SMTP id o21so3761890yho.29 for ; Thu, 19 Jul 2012 13:52:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:x-originating-ip:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=TIsgEFaxfZNEwNaFTSvk/JS8e8i4eBkbiuICmVY7p8M=; b=LEcpRa5xMgesgHl7LNqJhPX4X1dbi83Iv+Mjho+/bRnukaKdBQTI1rLjP7J+lmujvQ lgpBJmsfo98U9+C729m2bLQP/vtPZ+/C9Ij+H4nM4SHy+gg9Jb+ODAjx7jOdgwDU86K7 T+9hkE2EP9gD+1ylht0UMyPxpRdgIkdMXAjkLPbY9BhF/rTCVVLkgj01N38QQmQMkwBb 3nrlUk6zc0TYNkl24oESJpSGl6ViiOC9XxtW/64jkWNFQHviPO9m26n3TnANKD795TJw YVvtyE4MkACxhaLKmIEfKYD0ojOZJCnpMII4/S61UARrnJ53lUhcmZEOqLlyjZAzqjMa qTrg== MIME-Version: 1.0 Received: by 10.50.100.129 with SMTP id ey1mr2668551igb.35.1342731163830; Thu, 19 Jul 2012 13:52:43 -0700 (PDT) Sender: php@golemon.com Received: by 10.64.24.242 with HTTP; Thu, 19 Jul 2012 13:52:43 -0700 (PDT) X-Originating-IP: [2620:0:1cfe:28:8cb3:438e:1db2:b161] In-Reply-To: References: Date: Thu, 19 Jul 2012 13:52:43 -0700 X-Google-Sender-Auth: 1YsXfk0zc74SVA9l1jhqXhK2sPA Message-ID: To: Andrew Faulds Cc: internals Content-Type: multipart/alternative; boundary=e89a8f3b9c110c8a0004c534f639 X-Gm-Message-State: ALoCoQkcUdr4qS7sVUCaM6QlJD7978fimm1j0zdOUJdhd4uDXshNa6BLBGavvhiYOs5R8dGwSSsT Subject: Re: [PHP-DEV] Pseudo-objects (methods on arrays, strings, etc.) From: pollita@php.net (Sara Golemon) --e89a8f3b9c110c8a0004c534f639 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jul 16, 2012 at 4:27 PM, Andrew Faulds wrote: > I think PHP could benefit from making arrays, strings, integers, > floats, and possibly booleans, into "pseudo-objects". By this I mean > that they are not really objects (they are still primitive types and > keep their passing semantics), but they have methods. For instance, > instead of array_keys($array), one could do $array->keys(); How about just creating (in PEAR or PECL) a Php Type Library which lets you write all the new code you want which treats all these things in a Javaish OOP way, but leave PHP's functional roots alone? $str = new String("Foo"); if (3 == $str->length()) echo $str->toUpper(); I think automagically treating actual non-objects as objects is just asking for massive amounts of confusion. The technical debt PHP would take on from doing something like this would be... painful. If you *really* feel strongly about it, then I'd suggest you grab pecl/operator as a starting point and create an extension which hooks the opcodes involved in method calls to route to scalar handlers instead of producing the error message which they do now. If you want to get clever, you might even make the prototype classes for the scalar handlers extensible to override functionality in userspace, but don't tell anyone I suggested that. :) -Sara --e89a8f3b9c110c8a0004c534f639--