Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108063 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77065 invoked from network); 9 Jan 2020 16:40:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jan 2020 16:40:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E16971804F2 for ; Thu, 9 Jan 2020 06:46:21 -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-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 06:46:21 -0800 (PST) Received: by mail-lj1-f182.google.com with SMTP id l2so7513647lja.6 for ; Thu, 09 Jan 2020 06:46:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Xa6LcTmwpb9VdjVIxLRANUPWm6qXOHx9BXtfqQFiDro=; b=UopZrL0bQZRgS7UXj1Com5klWsEUZEr9g6rnR+bWrU+adxtBXifzEHyzt6kRtPkheF hs/UUwA2VMfLS8aljDKHRSZdCpjGAKC+7mhT5UyIvQoiu1gCXyqU7R5D1t2CjBFblLQ1 HzaTlcXSzJDEEI+UbmVnCYHnQ+fginPg/RaGT3fM0Y6VmZBgWAaR0JUGz+/dI34sisvW tpsl9WLFV2ySs2e8T1LUXl+fjV92a23wRdpPXaTpYKu5ybzy9PvO77R0Cn+7BG/Q4aXx hkc+Snivn6kGjds0opLFjlwhsthXvCrQSklpW1jd5bbvt5cPi4B2uZMiHKBu5bq5R+TU FZwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Xa6LcTmwpb9VdjVIxLRANUPWm6qXOHx9BXtfqQFiDro=; b=G9kbHXp5sNTSjTNy9xyR2AvNiL5Hj2UEsD7VUMdq//owb0p37lALALxyHFln0oPQtB zKkU/aUuMoaE+vRWvblKL9xshqRSMAnTq6O+zWbAaWni59HyC2yKQaJuYppPIDd8zfRq lISZEBypvr1ts9Hg5ooAsp0ciP85HysDsdrew60Msq/1c+KM2Nu8qfJ3glhrOIz0d4U/ rPDghRmwcsKwX0RkkGWqIIVYPqy4IZi5HKK+pm+7/g3Rssk7oz0urx34Ihw5zZIYDif3 dx9n+2EALNVOVWokUzcpBAPlNgiOxZtYHf1l8zFT2xcnriD644PY9bmReTWVBsP9OCtR 8KiQ== X-Gm-Message-State: APjAAAVqXnEH/BdaieBP1531JTfN3yZ4QONqE90H8CHqb6M/ZIX8qUYb TOf8B221N78LVKtYeJxPvYcODWpvRSMScuLrwWs= X-Google-Smtp-Source: APXvYqzjqmr8AiKwXl0Dd7I6F+EQcCJtW4U30Gs2AHDDEehVJNyiLkxuSLMn+qYtPY7nPA8orCTr1d2l0+sW2k7ELCE= X-Received: by 2002:a2e:9d89:: with SMTP id c9mr6833911ljj.129.1578581177647; Thu, 09 Jan 2020 06:46:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 9 Jan 2020 15:46:01 +0100 Message-ID: To: Bob Weinand Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000057ca1a059bb61293" Subject: Re: [PHP-DEV] Warn when declaring required parameter after optional one From: nikita.ppv@gmail.com (Nikita Popov) --00000000000057ca1a059bb61293 Content-Type: text/plain; charset="UTF-8" On Thu, Jan 9, 2020 at 2:41 PM Bob Weinand wrote: > Hey, > > While I generally agree that it likely is a bug in new code, I would > rather deprecate it than warn or even error: the change would make it > impossible to retain a type without warning while preserving compatibility > with an old PHP version and making incremental migrations harder (would > then not be possible to write warning-free code running on 7.0 and 8.0 at > the same time while retaining type information). > > I would like to see it deprecated and then removed in 4+ years. > Bob > As deprecation and later removal seem to be preferred by multiple people, I've changed the PR to implementation that instead. Nikita > > Am 09.01.2020 um 13:27 schrieb Nikita Popov : > > > > 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 > --00000000000057ca1a059bb61293--