Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113514 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42029 invoked from network); 14 Mar 2021 14:16:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Mar 2021 14:16:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7A6241804D3 for ; Sun, 14 Mar 2021 07:09:29 -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=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 ; Sun, 14 Mar 2021 07:09:28 -0700 (PDT) Received: by mail-ed1-f51.google.com with SMTP id h10so14225900edt.13 for ; Sun, 14 Mar 2021 07:09:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=DNE+4a2NiUG0AEXaW2FLTnx2W96zji/VDuEaIaUY6H0=; b=eUv/mSW0ysbV1AgaxMNSV6WM/7Lv7jJZtmjGcPBtTni3nZntWLonDySS8dADfDHAjM Ucnorv177tsdSiRYCp46h0bhIA5EzvKLEQzILjoSECyutLwHkYkUYW8VqG26yE/Gq3vG r8USaiOG9tVfaj11SiquN8NQyA6dq93ZABvfE9IpCju5QDSUnRw1apNU9tq8Ab9QgTKt 5fC57/atACxPo0GMDozojlq0Q4UMXxxoLc1Vycq3Mxqsxoc3/1x0shpjMQIVP3nzQdb+ WBvs5SbI/Hn0+T7AoM5ITFytFScXZEQsmxIivvYAtvM8PMDSiAgeemHSEqU/XZ6KE+Ka CFyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=DNE+4a2NiUG0AEXaW2FLTnx2W96zji/VDuEaIaUY6H0=; b=iC2+8jA+7kXcLs5QAtVfK3IrYymW3HUqhM4t8vttaqtif1lJG1Aa9cmCeGkHrJczgw nz9Q1BcKP1l1Jee7FRFthi7sjfiA49O2r67Kcarv87m2PEls06FoVfbH10LVJObhlCfF nwYiLnxT8l2NvBjQ3z67YGnRs7tebD4fiVqGjWwrlBxZshio9ajGT7OLkWajkXIYNAvV pqvJ458wq+JKszJmwETZ2JggY96PvapPzFeESzdu1Zqg6JiD9XYTKAX/u/80V/QrB+FU jOvzK/DJhNm2YywNhBrptKf6IYkohOIPnZZ40OVA8tixkLeGyVGIW/zE2myEQ76P/+zU KaHA== X-Gm-Message-State: AOAM530sJ5rHEMSOdvkCx4TvP/Jv6CpI30Lk4ri3D5zlrl8COQUeDW5O 7WsEM5sQeGhpjiHn88OaO+qIdpkiVOQ= X-Google-Smtp-Source: ABdhPJwNDq972xLQazjBNDmLfSUc8hMoAv0ArisG9Rmrx+ybfp4GCypEGjC3IVYEfZhgFCZvP95D9A== X-Received: by 2002:a50:fe06:: with SMTP id f6mr25158912edt.349.1615730967594; Sun, 14 Mar 2021 07:09:27 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id y12sm5745661ejb.104.2021.03.14.07.09.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 Mar 2021 07:09:27 -0700 (PDT) To: internals@lists.php.net References: Message-ID: Date: Sun, 14 Mar 2021 14:09:25 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] RFC: Add `println(string $data = ''): int` From: rowan.collins@gmail.com (Rowan Tommins) On 13/03/2021 19:54, tyson andre wrote: > I've created a new RFC https://wiki.php.net/rfc/println > This proposes adding a global function to PHP to > print a string followed by a unix newline (`\n`). Hi Tyson, I'm on the fence on this one: I've certainly had occasions when it would be useful, but mostly in quick prototypes and demo code, and just as often in HTML context (where I'd want it to add '
') as plain text context. I am not keen, however, on the proposed implementation details, and would prefer it to much more closely match either print or echo. - Until reading this RFC, I would not have guessed that printf() returned the number of bytes written; I guess it's useful in C, where you're managing string buffers, but in PHP it feels very arbitrary. I would also not particularly associate this new function with printf() so my immediate guess would be the same return value as print (even though that return value, int(1), is equally arbitrary). - You explicitly state that this function would depend on strict_types mode, but echo and print do not. I can't see any particular advantage to doing so, and 'println((string)$foo)' would be longer than 'print $foo,"\n"' rather defeating the purpose. - Most importantly, I accept your points about a function being more forward- and backward-compatible, but worry that not making it a keyword will lead to further confusion about how parentheses interact with echo and print. There is a common misconception that they have some kind of "optional parentheses", because they are usually used with a single expression, so wrapping it in parentheses usually doesn't change the outcome; but this is not the case, and it does sometimes matter. As currently proposed, I can see people getting nasty surprises from these inconsistencies. For instance: print (1+2)*3; // prints "9" println (1+2)*3; // prints "3\n"; unless strict_types=1 is in effect, in which case TypeError print ($foo ?? 'Foo') . ($bar ?? 'Bar'); // prints "FooBar" if both vars are null println ($foo ?? 'Foo') . ($bar ?? 'Bar'); // never prints $bar or "Bar", because they are not passed to println() if ( something() && println($foo) && somethingElse() )  // does what it looks like, if println is a normal function if ( something() && print($foo) && somethingElse() )  // does not print $foo, because the expression passed is actually ($foo)&&somethingElse() Regards, -- Rowan Tommins [IMSoP]