Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109014 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82107 invoked from network); 14 Mar 2020 17:05:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Mar 2020 17:05:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1F7F4180088 for ; Sat, 14 Mar 2020 08:27:41 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 14 Mar 2020 08:27:40 -0700 (PDT) Received: by mail-ot1-f46.google.com with SMTP id h17so13297362otn.7 for ; Sat, 14 Mar 2020 08:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=MhDI57qLIRbiIg5LiFVVOPPvhBSxwBRpRvSt1Yh0JKw=; b=VQldbGMbuhKV3tIqV30qjAq/QZIrO4zW2qYXb1pVelDVZeYY4y1CxIyCwCiK+VAI46 N90GZESsqBlXfguS5k4OlTCeixp2+FeyHxAxZdU+FvAvEyo8ojbBAMUXUiLAEbgz0SPN qmYHz1MX380o7NCSe2rtcwX9Yt10sPaNx/2qd8TjmWjrSiVwezFHfRRYUJI0cFWOwF0A NMjba48SOQNp1UezGPMlfEHq4TJeuVUdRjqeAhwa8FWa82+wkn8M6CGk3jmT5hB5oZF/ 4l4I1TmtH1B9tpeiokleCz6SlOU7dKBQdsvkRsuGnleOKqCdNlRiMu1vLzAlNVK/IgvM 9+CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=MhDI57qLIRbiIg5LiFVVOPPvhBSxwBRpRvSt1Yh0JKw=; b=VRW4TD+m8ieY46bPUVHSuQxiolmHZ9Dlx62M44oaXT4kOix9JSvpXe2m5Hd5uQJX49 6iYICXaRHtNTL+ukq781OofxXcjzhrLQYZvNT5wTT/AWp8jMT3XiY7Mv2uHCgxbFIoi9 qri0xG+SaXBKqfLxRy71mTpy74p04dkYe6uGlHUqFXNAcYjS2JowaXvn9zIBrRPkllTg R4DnSuACgLI81V/Oy/NeZmcaAk8spKjSVif8PhxJ3of48Ctno05PjDuvUNJJHokCzlV5 yT/ZeNUQcf+84uW1fALkxQz8HS+gif42QVB/fG0ACp4DxbCAbyDnxuCUH/kkV64tomYN t9XQ== X-Gm-Message-State: ANhLgQ1Brq5IxkBrbNJdxvxZ6I7CIAtgp/9QyHIyRG+X9gEnZDv8Ywk+ Eq2/1MIb9B1Ilktruc/KPNqlFteENtZreklrVVb9xdq38Fs= X-Google-Smtp-Source: ADFU+vvBcdNaeShR2M+c9BFr3r7ErTXg50rJIVm6AQYwk/6RRn+i24UhiWY/I1cF5bZ8mDEKzzF48bfKmvPYlP4WLM4= X-Received: by 2002:a05:6830:1285:: with SMTP id z5mr974084otp.241.1584199659855; Sat, 14 Mar 2020 08:27:39 -0700 (PDT) MIME-Version: 1.0 Date: Sat, 14 Mar 2020 12:27:26 -0300 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="000000000000faa1ca05a0d2396c" Subject: Argument with default value From: david.proweb@gmail.com (David Rodrigues) --000000000000faa1ca05a0d2396c Content-Type: text/plain; charset="UTF-8" Hello! 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 use 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 = []); public function __construct($data = 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 more specific way. public function test(int $pi = M_PI, int $a = null, int $b = 0) My suggestion would be to use the keyword "default" in the context of the argument. To avoid confusion, another keyword could be created, but I don't see why they confuse "default" as an argument and "default" for switch. test(default, 2) === test(M_PI, 2, 0) Atenciosamente, David Rodrigues --000000000000faa1ca05a0d2396c--