Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103796 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93536 invoked from network); 23 Jan 2019 16:44:12 -0000 Received: from unknown (HELO relay.alfa-bank.com) (217.12.96.18) by pb1.pair.com with SMTP; 23 Jan 2019 16:44:12 -0000 Received: from localhost (unknown [127.0.0.1]) by IMSVA (Postfix) with SMTP id B1FA5F209D; Wed, 23 Jan 2019 16:22:04 +0300 (+03) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alfabank.ru; s=mainstream; t=1548249724; bh=XqqE7a+x/O4N854EEUu9+LiynoU7e33vTWi9NfPAPZE=; h=To:From:Date; b=YaPzWLPXqEHPE8lW6gtsapumjEjeAsGwc4ZBqhDV/zzXR1xRCMIMfCrlBluqjLtv1 kp1oJUYtp2ECZ4zuFdws3Bh4KyWhh42kbRQ3pROYWkeQhwCL5E0S/qZ2bKQQrfts6a d2g+VmpKX9Km05z3tG9o0/25WiS/5aBiD1lDVdqw= Received: from relay.alfa-bank.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5CC72F207A for ; Wed, 23 Jan 2019 16:21:58 +0300 (+03) Received: from SMTP1.alfaintra.net (unknown [172.28.1.129]) by relay.alfa-bank.com (Postfix) with ESMTP for ; Wed, 23 Jan 2019 16:21:58 +0300 (+03) To: internals@lists.php.net MIME-Version: 1.0 X-KeepSent: 195997FB:D2057B04-4325838B:0047CA14; type=4; name=$KeepSent Message-ID: Date: Wed, 23 Jan 2019 16:21:59 +0300 X-MIMETrack: Serialize by Router on SMTP1/Internet(Release 9.0.1FP7|August 17, 2016) at 23.01.2019 16:21:58, Serialize complete at 23.01.2019 16:21:58 Content-Type: multipart/alternative; boundary="=_alternative 00496CB84325838B_=" X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSVA-9.1.0.1826-8.2.0.1013-24384.005 X-TMASE-Version: IMSVA-9.1.0.1826-8.2.1013-24384.005 X-TMASE-Result: 10--3.335200-10.000000 X-TMASE-MatchedRID: QW5G6BKkLTo4HKI/yaqRm2wbuvhCHs3c+KgiyLtJrSAAhmnHHeGnvaf9 v8vBNUVe1VkuYdrbp0ehIfz5Pq8buFfnsPC4h9MjkxIExNA2JIDFnoVLhjstj8UmcSma304TDYJ QbNnE3Z1YG6gtxfJf/O7G25QbWFfLzXJtm1treZxc/msUC5wFQfZfafJjZZIJasvzyM+NPkyBQA XMJI4fohraMUbyEA/tjQ0Dyi3xU1ItJMbDWD8p3khEDfw/93Buaja7DTpOGNbNsmTIwLSke6nTc WY2i/cA4vM1YF6AJbZO+3uGNcav91ZFWWuOwo7wymsk/wUE4hq3J+dAElvj0wY4hU1Ar1RGJnkC 7ajHIBOXeoaNkYx08NGGHl+y5ay22BMjgSQcByx8xd7m+4Nv71Rucqdu6vaWYzxmBXkhjKiE4wz xAGO/YdU54qFgBsUyA7DvohUiHXMKciAEMFwxuAyRQdmOZ/24a8OkLM1BZNgOEixqYc6EJhx5F8 Y9BBelFSns0VfGGSC6DnxS4FLt5w== X-TMASE-SNAP-Result: 1.821001.0001-0-2-1:0,12:0,22:0,33:0,34:0-0 Subject: Re: Proposal fo "Code-free constructors declaration" From: AGromov@alfabank.ru (Andrey O Gromov) --=_alternative 00496CB84325838B_= Content-Type: text/plain; charset="US-ASCII" >> Full description https://wiki.php.net/rfc/code_free_constructor >> Draft realisation https://github.com/php/php-src/compare/master...rjhdby:constructor >> >> "Code free" constructor is constructor with only purpose to directly set >> object properties from received parameters and, optionally, call parent >> constructor. >> >> Main idea is to move such constructor declaration inside class >> declaration. > I don't like the approach but I can change my mind. Currently, I see an > issue with your RFC: How do you add types with this syntax? Given this > syntax from the RFC: > >class MotorCycle($vendor, $cc){ > public $whells = 2; >}; > >class MyCustomMotorCycle($cc, $whells) extends MotorCycle("Custom", $cc){ }; > >How do you say that `public $cc` can be an integer for instance, so >expressing this `public int $cc`? My realization simply add "__construct" method into class via AST injection. Another words, code "($cc, $whells)" considered as zend_ast node "parameter_list" and accordingly processed by standart way. You can declare property type like you declare them inside standard method. Also you can declare defaults for parameters, use "..." notation (there is a nuance) and do everything else. class MyCustomMotorCycle(int $cc, int $whells = 3, ...$otherParams) extends MotorCycle("Custom", $cc){ }; --=_alternative 00496CB84325838B_=--