Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121507 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87554 invoked from network); 29 Oct 2023 11:35:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Oct 2023 11:35:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B1A8E180087 for ; Sun, 29 Oct 2023 04:35: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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 29 Oct 2023 04:35:50 -0700 (PDT) Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-40907b82ab9so26406235e9.1 for ; Sun, 29 Oct 2023 04:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=craigfrancis.co.uk; s=default; t=1698579348; x=1699184148; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=XhQAgk6Z1dBOJyb7GKlpCZfCABnj120T96EMruVBV2o=; b=YFM5nzDVv4QUqqXZRDvZvEq2eM5XwJUQTUDoZM11PDx6Cd90zM5QOz1tak197pqAM1 H3ZKmJaEhWXsIOrqCVcEhDLJdfK1ziSHHs+loEMTl2B2kDutWc7nbv9OP+fwqcoQJ+sP yaIkE4rUO8n6UjN43jX3HgFSPoVs10SFlbyL4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698579348; x=1699184148; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XhQAgk6Z1dBOJyb7GKlpCZfCABnj120T96EMruVBV2o=; b=SpIPjnBuMcR85cAz1hNpSKjefVn+CAuWPltHncFRFIlFVRQWq6AY4ZJ9li03Qspfst I0uMDClrAgf1QDo1r8ojiuiwMSl8igTu4E6PaWX+iQoyxEp0KUM8QaADZ025ol9wSytb jccnlrT9dlXQW+yetgTHRtEVHEW2/6eQMIMe+lXQ+CZy1o9LVw1gJzDeOZw0kxZMTBUb blj3eeqxqe3lm2wNW8lO+NAhtN1WbW0a4bgy8LzBiYPaI6GaZ18HIw9v840JGKaTcZ+e mOcpzEbiilyxocGgNzHxeEb7upP+b/LLnYtW+APSP0hgiUj5B7HxhelwgnZ8RVpS9d/T 2G0g== X-Gm-Message-State: AOJu0YwXOuKBAILkTYDxj8Eoax3fWDWXk3Rc8i+NDtlAJzb2AZ6CZlUc RBXkMdqI1QcZzZ1GzD5FoCL6zGKhCSVGIlxf4+BiOA== X-Google-Smtp-Source: AGHT+IGG59i8T5N1bCsi71paAUMOFVSqUVwisfu9JtMRhMwJ1t8TWffXD8ITBKHyyVFwX5UorJ5y/w== X-Received: by 2002:a05:6000:118b:b0:32d:a431:9045 with SMTP id g11-20020a056000118b00b0032da4319045mr8997406wrx.30.1698579348303; Sun, 29 Oct 2023 04:35:48 -0700 (PDT) Received: from smtpclient.apple ([92.238.103.248]) by smtp.gmail.com with ESMTPSA id m3-20020adffe43000000b003196b1bb528sm5777955wrs.64.2023.10.29.04.35.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2023 04:35:48 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_0B77842D-A685-4CDE-9481-C093F9EE2F35" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Date: Sun, 29 Oct 2023 11:35:37 +0000 In-Reply-To: Cc: PHP internals To: Kamil Tekiela References: X-Mailer: Apple Mail (2.3731.700.6) Subject: Re: [PHP-DEV] Passing null to parameter From: craig@craigfrancis.co.uk (Craig Francis) --Apple-Mail=_0B77842D-A685-4CDE-9481-C093F9EE2F35 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 29 Oct 2023, at 11:14, Kamil Tekiela wrote: > A code like this already throws a fatal error. >=20 > function enc(string $a){} > enc(null); >=20 > The only thing remaining to be fixed in PHP 9 is to make this error = consistent on all function invocations. Or, be consistent with all of the other type coercions? ``` function user_function(string $s, int $i, float $f, bool $b) { var_dump($s, $i, $f, $b); } =20 user_function('1', '1', '1', '1'); // string(1) "1" / int(1) / float(1) / bool(true) =20 user_function(2, 2, 2, 2); // string(1) "2" / int(2) / float(2) / bool(true) =20 user_function(3.3, 3.3, 3.3, 3.3); // string(3) "3.3" / int(3), lost precision / float(3.3) / bool(true) =20 user_function(false, false, false, false); // string(0) "" / int(0) / float(0) / bool(false) ``` The documentation does clearly say how NULL should be coerced: https://www.php.net/manual/en/language.types.string.php "null is always converted to an empty string." https://www.php.net/manual/en/language.types.integer.php "null is always converted to zero (0)." https://www.php.net/manual/en/language.types.float.php "For values of other types, the conversion is performed by converting = the value to int first and then to float" https://www.php.net/manual/en/language.types.boolean.php "When converting to bool, the following values are considered false = [...] the special type NULL" Maybe documentation should be amended to say "except when being passed = to a function"? Or, should we have fatal errors with the following as well: ``` $nullable =3D NULL; print($nullable); echo $nullable; printf('%s', $nullable); var_dump('A' . $nullable); var_dump(3 + $nullable); var_dump($nullable / 6); var_dump('' =3D=3D $nullable); ``` > Without it, you would never know that you have a logical error in your = code. But it's not an error? Craig --Apple-Mail=_0B77842D-A685-4CDE-9481-C093F9EE2F35--