Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69179 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19754 invoked from network); 18 Sep 2013 07:28:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Sep 2013 07:28:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=david@panmedia.co.nz; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david@panmedia.co.nz; sender-id=pass Received-SPF: pass (pb1.pair.com: domain panmedia.co.nz designates 209.85.212.171 as permitted sender) X-PHP-List-Original-Sender: david@panmedia.co.nz X-Host-Fingerprint: 209.85.212.171 mail-wi0-f171.google.com Received: from [209.85.212.171] ([209.85.212.171:44702] helo=mail-wi0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 13/41-13799-B2659325 for ; Wed, 18 Sep 2013 03:28:44 -0400 Received: by mail-wi0-f171.google.com with SMTP id hm2so5959476wib.16 for ; Wed, 18 Sep 2013 00:28:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=MJgOlJaki7kEGTLUIQlmPXRdEdImOe4ZhrnVAGMdxm8=; b=buGTjffZy6kL/jb1vqM5ZnQulj/7sEjYitf9zsHPOFSx93jffB9OLtFOPnFfGom7hR MsGWnFc4KjeO7/QMSrXgwrYMiIpzRf2ZjjGu+D8UKcSNGGw4TkvQ9QlCwlAA3amoTZ6z 7OukUMuioS1rmpXWb/+xdBohbxGSQG9cJLWxNe+YOZ3n28D5vTatY0Iw0mc8/R1+kF+B jhIJA7pAO3rawS5GpmxCsSYHukFPAa+xJRPVBuMo9/yPtSwxNB9Qe9ynJ4q+mBYPWUjJ 4uL6CKbUlqGVVrhQ1IaigCMSoq8t5oGp39+cYPKctnGQC3UIyLMugCquucqjrgLPZI4a Yb+Q== X-Gm-Message-State: ALoCoQmyCEax0Eqv7hO4Jwejn/jbWmDzvA/Td8+NRsz9XF7Z+MWZ0ek3ufx47Duwa/jzTYgWN/iB MIME-Version: 1.0 X-Received: by 10.194.85.198 with SMTP id j6mr271115wjz.51.1379489320787; Wed, 18 Sep 2013 00:28:40 -0700 (PDT) Sender: david@panmedia.co.nz Received: by 10.180.92.234 with HTTP; Wed, 18 Sep 2013 00:28:40 -0700 (PDT) X-Originating-IP: [118.90.90.110] In-Reply-To: References: Date: Wed, 18 Sep 2013 19:28:40 +1200 X-Google-Sender-Auth: XEIrrf2g58xeEXQVgDvrVwLplsQ Message-ID: To: Matthew Leverton Cc: Stuart Langley , Bob Weinand , Developers PHP Mailing List Content-Type: multipart/alternative; boundary=089e0103eea2efefd904e6a36292 Subject: Re: [PHP-DEV] [RFC] Keywords as identifiers From: david@pan.co.nz (David Neilsen) --089e0103eea2efefd904e6a36292 Content-Type: text/plain; charset=ISO-8859-1 *Should have been !== null On Wed, Sep 18, 2013 at 7:27 PM, David Neilsen wrote: > "missing any real-world examples of why it might be useful" > > One thing the I have run across in making my libraries, is the not being > able to call a function `default`. > > 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. > > Such as: > > class Foo { > public $default; > public function default($default = null) { > if ($default === null) { > return $this->default; > } > $this->default = $default; > return $this; > } > } > > 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. > > > On Wed, Sep 18, 2013 at 5:19 PM, Matthew Leverton wrote: > >> 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 >> of >> > 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. >> >> 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. >> >> Here's something that I've personally done with much shame: >> >> class Where >> { >> private function _or($lhs, $op = null, $rhs = null) >> { >> } >> >> public function __call($func_name, $args) >> { >> if ($func_name == 'or') >> return call_user_func_array([$this, '_or'], $args); >> } >> } >> >> $query->where('foo', '=', 1)->or('bar', '=', 2); >> >> 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. >> >> 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... >> >> -- >> Matthew Leverton >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > --089e0103eea2efefd904e6a36292--