Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103259 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10536 invoked from network); 25 Sep 2018 18:40:53 -0000 Received: from unknown (HELO mail-qt1-f170.google.com) (209.85.160.170) by pb1.pair.com with SMTP; 25 Sep 2018 18:40:53 -0000 Received: by mail-qt1-f170.google.com with SMTP id e9-v6so13225633qtp.7 for ; Tue, 25 Sep 2018 07:48:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8fC4dZ+qz/RuoEfeerRcOL49XkGkIMwxeM8KKoCbKuA=; b=grk+Hr2mfMwpoPEjjSoDFFiDlo0rkYGR9O5oTbmEu9e7yKEoO2qXj2/z3UkjvC3XlL IteRvlXBMrMVmZQHyGxveF+MbDjcaTSAr7ww7ParcmnGvJOkZlHiGdtUBStQKqf2yia/ d1zCMXnohKB07rcTtr8bo1HOhs/f77u01zLPPvb+LkbKZ6efJVAn48Ipyt0Ri/IJ6j2J 0ULg2yGAO8AAV+UmaW8LHuVSr+9wnIbxGf3Fwj7Hsdvv+wD37FVKT0Nwxt/nE8818nf/ c4SbkZxIezuoJw/qb7Tni41U3TLx4O/smhxT3JWbHdJpn4yLqFCnYhQkW/yugfu2czI0 vD+g== X-Gm-Message-State: ABuFfojXYM8PvRU3T+zNUVqIGUA95QPAqBYl22oYHtIYeM+T2AA/nlGL SAUylM+N27FRiZxPB98p64A3WkgpD6WJE6TDcL/kcA== X-Google-Smtp-Source: ACcGV60Gn4oSBFaW9NYSmfUgYiAxmgx2SR+LPo96Pjv/OJ2yAnaUjvAhwQOXjH0pBvJ1ZGHO/PUDEPuMvG678eItsF4= X-Received: by 2002:ac8:376c:: with SMTP id p41-v6mr1036020qtb.225.1537886926340; Tue, 25 Sep 2018 07:48:46 -0700 (PDT) MIME-Version: 1.0 References: <79483e23-7a28-aa05-5b74-bcfd52f57706@gmail.com> In-Reply-To: <79483e23-7a28-aa05-5b74-bcfd52f57706@gmail.com> Date: Tue, 25 Sep 2018 09:48:35 -0500 Message-ID: To: Stanislav Malyshev Cc: AGromov@alfabank.ru, PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Pre proposal for "Class extension functions" From: pollita@php.net (Sara Golemon) On Tue, Sep 25, 2018 at 1:50 AM Stanislav Malyshev wrote: > > I want to do RFS proposal for new language concept - Class extension > > functions. > > > > Syntax will looks like: > > > > function DateTime->localTime() { > > return $this->format('H:i'); > > } > > I feel this is inviting trouble. If you need additional functionality, > why not extend the class? Or write a function that accepts DateTime as > an argument? This encourages a style of programming where you never know > which object does what. Even in JS, as far as I know, it's not exactly > the recommended style. But in PHP I don't think we should be doing this. > I've been back-burnering this for a few days and I'm with Stas. I don't like this proposal because it adds complexity with relatively little benefit. If I wanted to add utility functions, I could create a proxy class which encapsulates the target and has a getter for passing into typehinted interfaces. You get all the functionality in any existing version of PHP without the added parser/engine complexity. Even static properties (which sadly lack get/set accessors) could be proxied using references so long as you know the statics ahead of time. -Sara