Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105848 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70317 invoked from network); 6 Jun 2019 13:10:05 -0000 Received: from unknown (HELO mail-lj1-f169.google.com) (209.85.208.169) by pb1.pair.com with SMTP; 6 Jun 2019 13:10:05 -0000 Received: by mail-lj1-f169.google.com with SMTP id a21so1462225ljh.7 for ; Thu, 06 Jun 2019 03:21:27 -0700 (PDT) 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=qrnM7T59CWj7I+17SsOBWvoYqpfgicvEhU+K0gthPzM=; b=njFN9l8enNvWPxYI4O/vZ3hN9S3qYKifvHcd2+XhGFlGH6c6+b1rJhnqsPywI9MiXb UnkT/3WWsVX/7tWL1dYdrGkgWPFvxAlFbo1Mt4Jw23JQPQaHiBawCTcJz3mdXpZ9boYO 1jFwa37ZSQ17oZIpufGFrpPRrYzkpz6rwoEobzfqZDkGCOLt2eihzyjGlcwNzVTaJUFg iRFBln+2BX4H+IEnKPMydziEnBUwcMNjhspLWFoaRyjUjwEWHeumZhPAdqXL0w5VG/Qe kgbB65f27kLzooUlmglp+44nppzbxWwSSzL05gKRlkPlRZ/MEZHWB2lEKXQp4Ce+AKaY rSpg== 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=qrnM7T59CWj7I+17SsOBWvoYqpfgicvEhU+K0gthPzM=; b=nsMqjkJUkGhsoW7dRVZJminRn/n6iEuA51aR4UGsWFqKHg7epiaVvll/73mNH4zjuG 0PKhsUzQe5BVVNelSWpLG6WurHVWlhS3VlmeAHarsm7XcWt4FTQCRRgQeKLGK7HNfMzR SV5bOtntqgh3NldqnoiHhpQ1eCyiL6r/abUEETBvrJQMyauLtH2lXJ5Un0d3JTRr/oMh t7vqp0Md3Jk4yufvPTCu8v5PnGoSyo9Kf9naf4tBqouynHAZB27l8MqpbynfoUI2cpDC eCNX6GTPq5RNEaZur/wno6wzHFM6CNsxHBFNcYNmAb5LWJXFluIQ+FvOf6FyPPzUlReP klSQ== X-Gm-Message-State: APjAAAVXEiBPivgFD9w7bxldQ2ioGebWjLDv8khT9BVHS4H8W4yWYLFN BOQt+JQm4hnBISnzphp650biaei57MVYr38dO0Y= X-Google-Smtp-Source: APXvYqxKMnjrX5PhOUsBJLNumNSSbuoaIpbfN0UGBUeOtRn3hN7CG9hPs0RRjo8PNPRfu3678lk48UAeaWvLwm8ipOM= X-Received: by 2002:a2e:3a01:: with SMTP id h1mr12060313lja.132.1559816487108; Thu, 06 Jun 2019 03:21:27 -0700 (PDT) MIME-Version: 1.0 References: <13220937.xxcDpnhvGA@mcmic-probook> In-Reply-To: <13220937.xxcDpnhvGA@mcmic-probook> Date: Thu, 6 Jun 2019 12:21:10 +0200 Message-ID: To: =?UTF-8?Q?C=C3=B4me_Chilliet?= Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000a11026058aa5135f" Subject: Re: [PHP-DEV] Handling of null arguments to internal functions From: nikita.ppv@gmail.com (Nikita Popov) --000000000000a11026058aa5135f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 6, 2019 at 12:10 PM C=C3=B4me Chilliet wrot= e: > I=E2=80=99m not sure if this is exactly the same topic, but one problem I= have > with how internal functions are handling arguments is how the absence of = an > optional argument is treated. > > I have stumbled across functions documented as functionname($arg1, $arg2 = =3D > NULL) which behaves differently when called as functionname('something') > and functionname('something', NULL). > A lot of places in the documentation state "if omitted" about an argument= . > > This is a big problem when several arguments are optional and you just > want to provide a value for the last one. You cannot know if giving the > default value for the ones in between will affect the behavior. > > Shouldn=E2=80=99t the argument parsing system treat absence the same as t= he > default value? > This is what happens for userland functions. > This is a somewhat different but closely related problem. The important thing to understand is that internal functions do not have a native concept of a default value. If you see a default value in the documentation, that's just documentation. On the implementation side, there is basically three ways in which defaults are typically handled: * Assigning a default to a zpp variable: Omitting the argument and passing that default value (but not null!) will behave the same. * Using a ! specifier: Omitting the argument and passing null will behave the same. * Checking the number of arguments: Omitting the argument and specifying it may result in differing behavior. If you see something that is documented as =3Dnull, but does not behave the same when null is passed, please do report a bug. The harder question is what to do about cases where the default is documented as "", and that "" value has abnormal behavior (i.e. is specially treated in implementation, the behavior does not fall out "naturally" from the empty string). In that case, I think we should also be accepting null as a value (independent of strict_types). There are probably a lot of functions that do this. Nikita --000000000000a11026058aa5135f--