Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103250 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 27243 invoked from network); 24 Sep 2018 20:09:09 -0000 Received: from unknown (HELO mail1.25mail.st) (206.123.115.54) by pb1.pair.com with SMTP; 24 Sep 2018 20:09:09 -0000 Received: from [10.0.1.11] (unknown [49.48.240.197]) by mail1.25mail.st (Postfix) with ESMTPSA id 623EE60487; Mon, 24 Sep 2018 16:16:43 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) In-Reply-To: Date: Mon, 24 Sep 2018 23:16:39 +0700 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <767727F3-4F9F-47AD-9E79-C3D2C0073EF2@koalephant.com> References: To: Andrey O Gromov X-Mailer: Apple Mail (2.3445.9.1) Subject: Re: [PHP-DEV] Pre proposal for "Class extension functions" From: php-lists@koalephant.com (Stephen Reay) > On 24 Sep 2018, at 6:21 pm, Andrey O Gromov = wrote: >=20 > Hello. >=20 > I want to do RFS proposal for new language concept - Class extension=20= > functions. >=20 > Syntax will looks like: >=20 > function DateTime->localTime() { > return $this->format('H:i'); > } >=20 > $date =3D new DateTime(); >=20 > echo $date->localTime(); >=20 >=20 > Realisation draft already written ( > = https://github.com/rjhdby/php-src/commit/a54d7d3f8504d2e15908bb0e44de0b2f8= 7683872 > ) >=20 > It is interesting or not? =46rom a user land perspective, I think this is a proverbial truck of = boxes of cans of worms. For reference: monkey patching methods onto built-in classes is what = gives you shenanigans like the discussion about `[].smoosh` in = Javascript. This just opens up a ridiculously wide scope for =E2=80=9Cwe can=E2=80=99t= add method X because of a BC break in userland code=E2=80=9D. The *only* way I could get behind this, is if it=E2=80=99s made clear in = the docs/RFC/wiki/written in the sky/etched on the moon via laser, that = literally no future RFC will ever consider =E2=80=9Ca user land BC break = because of =E2=80=98class extension functions=E2=80=99 in the wild" a = valid reason to reject the RFC. The only officially supported use of = this, should be for the one good use of monkey patching in JS: polyfills = for missing functionality in older runtimes. For example, SplFileObject = was added in PHP 5.1.0, but didn=E2=80=99t have an fread() method until = 5.5.11. Cheers Stephen