Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61328 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68766 invoked from network); 17 Jul 2012 00:12:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jul 2012 00:12:26 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:38830] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/11-62735-7EDA4005 for ; Mon, 16 Jul 2012 20:12:24 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 798C7700044B; Tue, 17 Jul 2012 01:12:20 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id z7Jzcc1v9paM; Tue, 17 Jul 2012 01:12:20 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 1CE3F7000432; Tue, 17 Jul 2012 01:12:20 +0100 (WEST) Received: from damnation (unknown [IPv6:2001:470:94a2:4:14dc:22a:24cf:10db]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 405A12005293; Tue, 17 Jul 2012 01:12:19 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals , "Andrew Faulds" References: Date: Tue, 17 Jul 2012 02:12:14 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/12.50 (Linux) Subject: Re: [PHP-DEV] Pseudo-objects (methods on arrays, strings, etc.) From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") Em Tue, 17 Jul 2012 01:27:10 +0200, Andrew Faulds escreveu: > Through its history, PHP has slowly become more object-oriented. PHP > today has classes, interfaces, objects, namespaces, and so on. > However, much of the language's core functionality is entirely > procedural, composed of functions and constants, much of which are > badly organised and inconsistently named. > > 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(); > > Adding this would make PHP feel more modern and allow people to > embrace more object-oriented programming styles. As a bonus, it would > also give a chance to make the string/array/etc functions better and > more consistently named and possibly implemented. > As I said in IRC, I have some reservations about this. Let's ignore empty arguments like "make[s] PHP feel modern". That aside, the main argument advanced in this message makes no sense. Adding method call syntax to arrays hardly makes PHP more object oriented. Syntax is unimportant. There's no substantial difference between array_slice($arr, ...) and $arr->slice(...). Object orientation is about polymorphism, encapsulation, inheritance, etc. None of that is advanced by the proposed change. And even if it was, you would still have to justify why that would be a positive development. Plus, it's very odd to claim this would make PHP more object oriented when there are no objects involved! I don't think it's necessary to enumerate all the differences between objects and arrays -- one that would be particularly confusing would be the different passing semantics (or more accurately, different levels of indirection). There is, in my opinion, *one* merit here -- redesigning -- and perhaps reimplementing -- the arrays functions API. This will require a lot of work, thought, and time tough. -- Gustavo Lopes