Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69178 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18384 invoked from network); 18 Sep 2013 07:27:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Sep 2013 07:27:52 -0000 Authentication-Results: pb1.pair.com header.from=david@panmedia.co.nz; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=david@panmedia.co.nz; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain panmedia.co.nz designates 209.85.212.169 as permitted sender) X-PHP-List-Original-Sender: david@panmedia.co.nz X-Host-Fingerprint: 209.85.212.169 mail-wi0-f169.google.com Received: from [209.85.212.169] ([209.85.212.169:35905] helo=mail-wi0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/F0-13799-6F559325 for ; Wed, 18 Sep 2013 03:27:51 -0400 Received: by mail-wi0-f169.google.com with SMTP id hj3so5960135wib.4 for ; Wed, 18 Sep 2013 00:27:47 -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=8bU3z838icpPyfmb2Tx4o9Jed659PNm0qQpGg3dQoOI=; b=SqGk8zQF9ZIoHdFxJXfZ7fev+BxNYU+mKCe/vB9BAqtj0dredkjvHRLO5bsKhe/bYB 1I/08v+Jzqca2fNlf8aUMhZGLzzzwfCTBiVSbZucqJnvEyhahRaBdlP9X5MTOtDO8gNm dnvCwY4qAqsmAxz3MT/pCnoBfE/V2G/7VfXVzsdsnQbJCdEasAdAgcxNMkIEV7Y3JxnS +ZDpxvEiIUk1oPkryQ4sSY4W3CXVJpS1lm43/DtGmKYXleqVnrcoqzAPhkGOXAK3lzu4 1O+OLoi8Y+RrI30VQbBUilah31z3OuPYThYIKMX2r6bz/ZFS7L7O9e2+s28IbmtmPg7I n1pg== X-Gm-Message-State: ALoCoQnMeZhNR/ns3vksu0dB/BXJsDwOGP1EnqmH8qkg8ubdzpczBO5O0aJ2fd70Ukv/3Dlzp/0W MIME-Version: 1.0 X-Received: by 10.194.122.99 with SMTP id lr3mr29682484wjb.21.1379489267330; Wed, 18 Sep 2013 00:27:47 -0700 (PDT) Sender: david@panmedia.co.nz Received: by 10.180.92.234 with HTTP; Wed, 18 Sep 2013 00:27:47 -0700 (PDT) X-Originating-IP: [118.90.90.110] In-Reply-To: References: Date: Wed, 18 Sep 2013 19:27:47 +1200 X-Google-Sender-Auth: u9x6v2B1mTmuiJyX-w_tSG6ctyI Message-ID: To: Matthew Leverton Cc: Stuart Langley , Bob Weinand , Developers PHP Mailing List Content-Type: multipart/alternative; boundary=089e011779b5c03fb904e6a35f9d Subject: Re: [PHP-DEV] [RFC] Keywords as identifiers From: david@pan.co.nz (David Neilsen) --089e011779b5c03fb904e6a35f9d Content-Type: text/plain; charset=ISO-8859-1 "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 > > --089e011779b5c03fb904e6a35f9d--