Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69184 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56641 invoked from network); 18 Sep 2013 12:01:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Sep 2013 12:01:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 157.55.1.144 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 157.55.1.144 dub0-omc2-s5.dub0.hotmail.com Windows 2000 SP4, XP SP1 Received: from [157.55.1.144] ([157.55.1.144:58649] helo=dub0-omc2-s5.dub0.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/C2-43258-01699325 for ; Wed, 18 Sep 2013 08:01:21 -0400 Received: from DUB406-EAS201 ([157.55.1.137]) by dub0-omc2-s5.dub0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 18 Sep 2013 05:01:17 -0700 X-TMN: [YaLhQh1wdJb0zSvQGr4DF0ic0WC7/pKR] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable References: MIME-Version: 1.0 (1.0) In-Reply-To: Date: Wed, 18 Sep 2013 14:01:07 +0200 To: David Neilsen , Matthew Leverton , Stuart Langley CC: Developers PHP Mailing List X-OriginalArrivalTime: 18 Sep 2013 12:01:17.0814 (UTC) FILETIME=[C8295960:01CEB466] Subject: Re: [PHP-DEV] [RFC] Keywords as identifiers From: bobwei9@hotmail.com (Bob Weinand) Am 18.09.2013 um 09:28 schrieb "David Neilsen" : > "missing any real-world examples of why it might be useful" >=20 > One thing the I have run across in making my libraries, is the not being > able to call a function `default`. >=20 > I use the chainable getter/setter in one syntax a lot (a la jQuery). Hence= > when I have a class with a property named default, and can not make a > method in that sense. It makes my API inconsistent as I have to use a > getDefault, setDefault, when every other method is a single word. >=20 > Such as: >=20 > class Foo { > public $default; > public function default($default =3D null) { > if ($default =3D=3D=3D null) { > return $this->default; > } > $this->default =3D $default; > return $this; > } > } >=20 > This might not be the prefered way to write methods, but I don't see why > the language should restrict me from doing so because the word default is > used in a different context. >=20 >=20 > On Wed, Sep 18, 2013 at 5:19 PM, Matthew Leverton wrot= e: >=20 >> On Tue, Sep 17, 2013 at 7:50 PM, Stuart Langley >> wrote: >>> To be honest, looking at the example in the RFC, being able to define a >>> member function 'new' on a class that completely changes the semantics o= f >>> the new operator is a great example of why you would not want this >> feature. >> It doesn't change anything because $foo->new() has no intrinsic >> meaning in PHP. And I don't think the argument "the programmer might >> do something stupid" ever holds much weight as a no vote against >> anything. If somebody wants to create a confusing misnomer, he doesn't >> need this proposed feature to do so. >>=20 >> But I agree that the RFC is missing any real-world examples of why it >> might be useful, and that any new language feature should have >> real-world benefits. Hopefully some more compelling reasons will be >> added to the RFC. >>=20 >> Here's something that I've personally done with much shame: >>=20 >> class Where >> { >> private function _or($lhs, $op =3D null, $rhs =3D null) >> { >> } >>=20 >> public function __call($func_name, $args) >> { >> if ($func_name =3D=3D 'or') >> return call_user_func_array([$this, '_or'], $args); >> } >> } >>=20 >> $query->where('foo', '=3D', 1)->or('bar', '=3D', 2); >>=20 >> Imagine that $query->where() returns a Where object. I really want an >> "or" method because it make things concise & readable, but this is not >> allowed. So I override the __call method to add such functionality, >> which adds useless overhead. >>=20 >> There are a few keywords, such as list and unset, that I often wish I >> could use in PHP. So in terms of readability, I think any sane >> programmer would use this proposed functionality for good... >>=20 >> -- >> Matthew Leverton Thank you all for your feedback; I was effectively missing a few concrete ex= amples. I now added some examples. Bob Weinand=