Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103270 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92396 invoked from network); 27 Sep 2018 19:07:30 -0000 Received: from unknown (HELO relay.alfa-bank.info) (217.12.96.27) by pb1.pair.com with SMTP; 27 Sep 2018 19:07:30 -0000 Received: from localhost (unknown [127.0.0.1]) by IMSVA (Postfix) with SMTP id EF9AC6E1D6; Thu, 27 Sep 2018 18:15:52 +0300 (+03) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alfabank.ru; s=mainstream; t=1538061353; bh=jE7qA5VCVcWa9KEeqL4CTpKjypiEkfr7X1mz++DnSQ4=; h=To:From:Date; b=pO3R+xO6ai5QbIc9IoMkZvMsYocpDQUAOMQfAgxYHWC+/XVLENxt0Yy8iBRII1VYw M4GMDhOcLJ82JX2TU0FHThhlLGwjvWVOt/FQYPprHDOhcoxeSyDGg8Je1BmcYHznA2 aRNgHgJdZg4AnVdljKjzifyvLJ+TK1B5n+5WmEVU= Received: from relay.alfa-bank.info (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AFF036E1AF for ; Thu, 27 Sep 2018 18:15:51 +0300 (+03) Received: from SMTP1.alfaintra.net (unknown [172.28.1.129]) by relay.alfa-bank.info (Postfix) with ESMTP for ; Thu, 27 Sep 2018 18:15:51 +0300 (+03) In-Reply-To: References: <1537824239.902316.28693.59265@mail.rambler.ru> To: internals@lists.php.net MIME-Version: 1.0 X-KeepSent: D1A5980F:B2DDB83E-43258315:004F80A0; type=4; name=$KeepSent Message-ID: Date: Thu, 27 Sep 2018 18:15:50 +0300 X-MIMETrack: Serialize by Router on SMTP1/Internet(Release 9.0.1FP7|August 17, 2016) at 27.09.2018 18:15:51, Serialize complete at 27.09.2018 18:15:51 Content-Type: multipart/alternative; boundary="=_alternative 0053D89843258315_=" X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSVA-9.1.0.1826-8.2.0.1013-24120.005 X-TMASE-Version: IMSVA-9.1.0.1826-8.2.1013-24120.005 X-TMASE-Result: 10--13.003200-10.000000 X-TMASE-MatchedRID: YCrZ6eUT3emN/VOMfeOgV20PWqD0pliRFgk0ZPECSsE3XlVVGX0OkXEJ 8hKuM/+zi1QrJgu0we/70SaVHefKTgxx42eKnLbpo65WJt1k1O+FKXsoBdprwtTFL12ty323XlT d2Oire2Pu9z76et7Do06aTm1klXkoGN63p9ap1YpgP1dNF1ow7W0U3Ma4EPnvx4gLGRC6FAMmtv KBNiORf1SBhWzL73BXIBZeGe1916JXXpy2x9BP/5D6BbDN9+jOknjBMY7iKBLIXwWZDwrVt4lbX igDnfa4hWi4pSZYsD+lU79O0CObkWrP4F2ArGDgNNHZMWDTEbeL/KYnYVWDlC1TMvojbNdJo8WM kQWv6iXgT2zXYa9/nXsQ35Yt9gBIYa6lrDp+os3uuTu83nWXPHkAF90OC35bORCo4NRA8JpGI6J DO3+VaJhhMujqQtMn+SUAtcT//VlrJYHbgCT874OImExrQmeWS1cXmyVCrIc= X-TMASE-SNAP-Result: 1.821001.0001-0-2-1:0,12:0,22:0,33:0,34:0-0 Subject: HA: Re: [PHP-DEV] Re: Pre proposal for "Class extension functions" From: AGromov@alfabank.ru (Andrey O Gromov) --=_alternative 0053D89843258315_= Content-Type: text/plain; charset="US-ASCII" I think that it is good idea to write page on RFC wiki with detailed descriptions, examples and motivations. I see that it can't be accepted in nearest future, but let it be for history. :) There is many open questions. I will try to resolve that I can. >>> Bring a little Javascript into PHP? >> In fact, I looked at Kotlin :) > Kotlin does not modify classes. > This sort of thing is sound in compiled languages like Kotlin and C#, where > this is really syntactic sugar for calling user-defined functions with > object-like syntax - it's possible (and sound) *only* because these > languages can resolve such calls at compile-time. Yes, I understand it. At the beginning I'm trying to find way for Kotlin style realization - function with receiver. But, unfortunately, it seems almost impossible if keep it simple. > where this is really syntactic sugar Exactly. I'm positioning this as syntactic sugar. And very useful sugar I hope. > In dynamic languages like JavaScript, you're literally writing to a > map of methods, which means execution order is critical, and overwrites are possible Need some advice. Why execution order is critical? Inserting into `ce->functions_list` maked at compile time, and overwtites will be checked at this time too. > What's wrong with just calling a function and passing the object as argument? Nothing but aesthetic sense. For example, PDO. Classic way: $stmt = $db->prepare($sql); $stmt->execute(); $oneValue = $stmt->fetch(PDO::FETCH_NUMERIC)[0]??$default; Standart function way function takeOne($db, $sql, $default){ //see "classic way" return $value; } $oneValue = takeOne($db, $sql, $default); This is looks not good for me. - 3 arguments - no intuitive connection to $db - "takeOne" placed in global functions scope for simple utility logic. Proxy class method. Let me do not write monstrous wrapper over PDO? Extension function style function PDO->takeOne($sql, $default){ //see "classic way" return $value; } $oneValue = $db->takeOne($sql, $default); - Intuitive connection to $db. - "takeOne" encapsulated inside PDO class --=_alternative 0053D89843258315_=--