Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108052 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42408 invoked from network); 9 Jan 2020 14:21:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jan 2020 14:21:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F0EAE1804A8 for ; Thu, 9 Jan 2020 04:26:57 -0800 (PST) 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,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-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 ; Thu, 9 Jan 2020 04:26:56 -0800 (PST) Received: by mail-lj1-f180.google.com with SMTP id y4so6992942ljj.9 for ; Thu, 09 Jan 2020 04:26:56 -0800 (PST) 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=+LHGOtUgWBU/s5nwsPhJUY/p/j30WaUYuqc12yqgL78=; b=GJIYYYeRsDHLJMUeGIxAl5EpBFdeeDF6q6eic0DdCUGnKptJS6GmPQnIdjnqPo1xBj mi29241VHn5sSjxApBeY3XO/6TyBC4r6vY01Vml560e/xwd6lyc2L0xR3n/XaLtK4sOs EZg1dO/5VnmLxLpjyNeAtUHAW62qgtWRXTGkSqWWUdu7WYoeKekhtX9p1/W67oinFF/1 BsK7Otnuw+OczGNb6wZS1LOT6u+roe5FjgO6I6gcXmq/Y88sCkn0UKmqg8SkVRAbOU4m TGtECh1ZE4ZSzYjz0oLfe0J2JtDW7oBK6l3X/rU19tESGB8Pdz+mIpIgDA28zgz9Vvuo E1+A== 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=+LHGOtUgWBU/s5nwsPhJUY/p/j30WaUYuqc12yqgL78=; b=NsqJjwG/kU1GQJYLAJExnyODDa9xoOqfO6jpQJ8Z3ziIERf57EwtN4QxgorrfkkdTj MGmcAYVe23smDexydN1mXQn9Ppkmt7F6bP7fReUtPYs1QX9anuHgZGQXPC58lMXB02K8 R9rd5rS9/0MBRoomNfwTZ756Rl95hnxFtCSuI3Jw95hwBpbERDqlwoLiS4EQPSUV3XgH NfAClFj/IqgrE518gFk/XX7NdgTjK1G7ecvhcq8aRo56u1Q1xavT64SWxZjRezlaWX3h Hnh8FOwUtAJfU95+CwOSKzS6QqeiC0gSP6Sjb3N7OQFneAHcb+cf6WO+FLjxyAmq3EnD YiqQ== X-Gm-Message-State: APjAAAUnp1KEjmJNetSTXZF7n4tY5APmzcVyOgP6in6Tr3fsFBjC/5hr jzxLwDf2YgUmjO8rV88m2zFe41/dKzSlK2gBgUg3p9Den9c= X-Google-Smtp-Source: APXvYqxkQxThdAIu7m/g56W1igrdjoznamjXIe3QAwus4TeoAJc7S+snbKBKoFo8QjS46h80SCu4EMk0FGWePhYSBsQ= X-Received: by 2002:a2e:5304:: with SMTP id h4mr1181630ljb.75.1578572811537; Thu, 09 Jan 2020 04:26:51 -0800 (PST) MIME-Version: 1.0 Date: Thu, 9 Jan 2020 13:26:35 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000af1b76059bb41fa0" Subject: Warn when declaring required parameter after optional one From: nikita.ppv@gmail.com (Nikita Popov) --000000000000af1b76059bb41fa0 Content-Type: text/plain; charset="UTF-8" Hi internals, I've created https://github.com/php/php-src/pull/5067 to make code like function test($foo = null, $bar) {} throw a warning: Warning: Required parameter $bar follows optional parameter Historically, having an "optional" parameter before a required one was useful for poor man's nullable types. That is, one could write function test(FooBar $param = null, $param2) to get an effective function test(?FooBar $param, $param2) signature on old PHP versions that did not have native support for nullable types. Since nullable types have been available since PHP 7.1, having a required parameter after an optional one is increasingly likely a bug rather than an intentional workaround, so I think it would be good to throw a warning for this case. What do you think? Nikita --000000000000af1b76059bb41fa0--