Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109016 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88302 invoked from network); 14 Mar 2020 17:30:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Mar 2020 17:30:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B36E51801FD for ; Sat, 14 Mar 2020 08:52:50 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8560 212.227.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 14 Mar 2020 08:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1584201167; bh=iTFHZ2SZLZAZyMP4VkJPRbqUPOcEuZVqASCHNDc/E0Q=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=FNPPas8doapW61ddC7FWP5lLWZkYcdP+oIQ5zJZzVFW9d5apCnIe9JjaP+J7N6E0Q cbZ7BGW09wf2QP6gOU2szS6F6B4efExspVepHwfnMNrjmBdOnhJpGBAy05G37fHNMs mnP4e2D+k/WXScCWj5ZfoSpfDoBntYHr04x5YG/k= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.2.130] ([79.222.41.175]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MLQxX-1iwItU01HX-00IV0e; Sat, 14 Mar 2020 16:52:47 +0100 To: David Rodrigues , PHP Internals References: Message-ID: Date: Sat, 14 Mar 2020 16:52:42 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:lGewbir2to4s/YjneGCUa+Qb8GB4+606PEK0u+Qx7Z5FFoymdwc z299HkKNLDyAibgPnS3ks/J0Do07AjGlk2QfeWbBkvJE5jHj7fipWldJ+ezhgVj5m+QcBxf cNjJFwQm7PmD5eK8v/Y9IfXcfHfFerQz1NOtamQ2yR4S3GjrAJYt966n49/3ieoq3HxXtTd WaEqAwgHp+4ff0swcRlow== X-UI-Out-Filterresults: notjunk:1;V03:K0:F0Kt7BW3VQU=:8Z5bUl8P5W0DpjcImS5lq0 BkJuoZUJv16rRYwsXYU1uQUr3hw8uaUhbpm4JcBAUIuaKO9DkwrM1r8W56R1Gf/Wa+caMMbmM UIz+V+I6rlINlZCUzaw8yeD5Dabaz0+bmPDdXyQurXVuxzb3wVJ/fm3v0eieVePWNCZpREFv7 xPy5brVorSU/uvWMI7AcQMw/JVFMgVvv//ecDIar0nvdiyPWwAcVQuyf/tIq+upjhjDWm0nZz NFg0Lned9X/66LN6/9EPXOcg8y1qn5Rm75Ass9LKgz9mZ6QXNDxC62X0mPZkMprhDuvBecQ0P i72IwPS400gii21CzG9iZ1TZ9zlfPCrD/Ak6V/HKdPYlF3UcWieSoJck4GPamOroOxOhGBUBZ lD9o2Cq2WcfcF08sFKr1R3KJkHL5AC9FBqeBfBdlfkjdE8Ok/BJuhPSYcxT10xYD+EoZQOVN9 MQcofZqvNLeqB/lAGDE5iLDj18To/sx6hDHw3uVfZKEZ2ZhhNbt7QnTRH2JWy0MOIxitCSCJX JPfcmBpUrw6mo1i1kIq0naeXzCqDMo48KFz1tPaBxp6aIPy0DE/BsT/PZ3gaWvKDsI3k0ETAf WUgC6U4i9oKjjPJsqAyo1oIE7/+3XsehVHHXAw2yJ0nQMpNNOpCxvK5LUeuUkGADFwgnNDYRp 2gAxBO7AHTcx5Lu4SJew7ZHfxBylGQAXQh8fHLTlz8W407obnUt3NXbNPjkg/STvrDAU9Tp6u o/4LwiR+6T9yPImyssHUxp7DpeRlwGXWNui3EI4C9PXdkgBqPKH/yKuc54yZAC752ETuSH9BM m5hgNVuvli0rkgvKEN6ks+BB+i+a/5RcI1GpX6OJgaFOdJn7c4U47JdyUhBQg8B+5U06EkFJ1 5DTOTcIH1FLQAf8SBoZIw1ex6sOsKWNs0/8Pog24vX7cdocfdyNgDVXRGUrHHibVWRuxQ20yC gBYBknTBT+TBJxy04YoavqJvzeHBbQhJRzArnz4g6XzxIbOndLjX/odduHzJi4RfEoEGviu2C yDjvIDHzB71hvDGIQRdugxznUNcQ8BdGHaY+Q5Z/efGW69fBPshaH0BOuTZwTGMLwgYXapZ2z r0SPq6+UKZvwtbrej5QATruEy/1fOt6FBFzXIvRRyKWx5Pk3+epSHiAtBuzaGSWzMlfB8o9p7 pVZqZUFQe37qTfyqxCLNwES2sNXwmEme7lZQT4Fj49qk3MVGa5ZlyEwVUeTX7KXXQVUVpusaR Rhhg2f8xwKTutPiMH Subject: Re: Argument with default value From: cmbecker69@gmx.de ("Christoph M. Becker") On 14.03.2020 at 16:27, David Rodrigues wrote: > I would like to propose the idea of having a keyword that can be used to > use the default value of a parameter, without necessarily having to know > it. Since PHP is not a strong typing language, the default values they u= se > are quite mixed, and it is difficult to predict each without knowing the > documentation (if you have documented it) or using IDE support. > > public function __construct($data =3D []); > public function __construct($data =3D null); > > I always prefer to use null as the default value to optional parameter, = and > then define the value transformation in case it is null. But a lot of > third-party code defines how they want the default value. > > String: null or '' > Array: null or [] > Integer: null or 0 > Boolean: null, true or false > > In addition to other values that can actually be used as defaults in a m= ore > specific way. > > public function test(int $pi =3D M_PI, int $a =3D null, int $b =3D 0) > > My suggestion would be to use the keyword "default" in the context of th= e > argument. To avoid confusion, another keyword could be created, but I do= n't > see why they confuse "default" as an argument and "default" for switch. > > test(default, 2) =3D=3D=3D test(M_PI, 2, 0) FWIW, this has been proposed as RFC[1] quite a while ago, but has been declined. [1] =2D- Christoph M. Becker