Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113517 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51772 invoked from network); 14 Mar 2021 16:27:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Mar 2021 16:27:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 622801804C0 for ; Sun, 14 Mar 2021 09:20:49 -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,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 09:20:48 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id bm21so62249689ejb.4 for ; Sun, 14 Mar 2021 09:20:48 -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=4iv3pH0TymNcEsF9f7YhtsudyNpZEY2Q3qAXwPRAewg=; b=jmtKjGAdsLjxG5ltxDtuwnibwh+3nmrWLCxLyTln7dJyY3Xr88M66PK6/spfIfRl+6 v7vg5l8X8OMn2iuyJ2wB42Z1QgJC+oS2lfyh4T20vcM7o7mP8oNXFUKlsgXSp4Fvb/Pe ZcoYEFtbTFhG1Jqr982GM3qymYD6zeVyFHWVUfTNGBsrqlxItY9op9A6nrOnoaqf6EK0 S5Kq7DzzAJW65xPeJBOHytP20jnPrnq5g1850WVtpOX97O14pDp0SLvqTn9Rje5s7B3T 2Zt0ysip573TryD9DBNW1SxbYMefcHAnPFL0ClVXR5MDgBlruX9nazAftHu/A27/TfdD tKaw== 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=4iv3pH0TymNcEsF9f7YhtsudyNpZEY2Q3qAXwPRAewg=; b=erBUYN3roNfHW7LHXdVuMbTJgOunRSkZaffgxKROEAO3TvU/NDShNWOc4ZCzcq1NPs k8rO19px7HZF6cefeP2gFwnDajCAu/b/2R3evou5NrDDMaW28MzeMXYEz1tWWYnFqmCL JWSAoeGaGwik7A+4d9oQgnOEQmH3P3NLBK4SwScTF1hKJWPO/UnBWzkPjgTeph8nH7NT aM1CxKokP2dG8pZS7QYA/7jaYzzZwuot1mJWyQeLDHWIptTMvcCaXkasPFQOjArbz+Sd oYe5LRngcNOS0ZWBoKB1g9XGjldi5EFe44NZh0FGk7vowG4K8GelouUI8i2sPC2Rc963 y1eQ== X-Gm-Message-State: AOAM531n2xVZMYnaau3frenEg7q/8p98dQEB5LIYw6IqgLvgUNMplNXC DbP+DJUtxZBPSvuOcB4jOzzaZiN8Iv0= X-Google-Smtp-Source: ABdhPJxlo9LSXe2uAtzOawfTHDUfX3FIwmWNyFnRSJpNPfu/xXu81q5rdA5cNsV9jjKII77e3/0QpA== X-Received: by 2002:a17:907:3ea0:: with SMTP id hs32mr18943609ejc.411.1615738846550; Sun, 14 Mar 2021 09:20:46 -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 c20sm5954338eja.22.2021.03.14.09.20.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 Mar 2021 09:20:45 -0700 (PDT) To: internals@lists.php.net References: Message-ID: Date: Sun, 14 Mar 2021 16:20:45 +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 14/03/2021 15:52, tyson andre wrote: > There's also the alias fputs ofhttps://www.php.net/manual/en/function.fwrite.php > which also returns the byte count. Notably, like printf(), that is borrowed directly from C, and probably dates from a time when most PHP programmers were also C programmers. That time is long past. > Annoyingly, any decision I make would be inconsistent with something I'm not sure why you're casting your net so wide. The name and use cases for this function put it squarely next to "print" and "echo" in my mind, and it would never occur to me to ask if it was consistent with most of the functions you've mentioned. > It definitely would be longer to use `println((string)$foo)`, > but there may be cases where that would be done, > e.g. if you are writing a script that would be reviewed/modified/used by > programmers that are more familiar with languages that aren't PHP. > (It'd be more readable using 1 output method than 3) Sorry, I'm not sure what you mean here. What 3 output methods are you talking about, and how does println((string)$foo) make a difference to them? > There's also `println("$foo");` Which is still marginally longer than the existing print "$foo\n"; > Static analyzers for PHP such as Phan warn about the unused result of multiplication > to catch cases like this, and other analyzers can easily add this check if they don't already check for it. > https://github.com/phan/phan/wiki/Issue-Types-Caught-by-Phan#phannoopbinaryoperator That doesn't stop it being a nasty surprise. People will want to use "print" and "println" interchangeably, and making that difficult because they have different syntax is going to end up on lists of "things I hate about PHP", no matter how easily tools can spot it. >> 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() > The fact that `print` doesn't require parenthesis is something that surprised me initially, Just to be clear, it is not that print doesn't *require* parentheses, it's that print does not have parentheses, ever. > though changing it to force it to use function syntax would be a much larger bc break > more suitable for a major version, that I don't expect to pass. It hadn't even occurred to me to suggest that. I was suggesting the opposite: if we add something called "println", it should have identical syntax and behaviour to "print". The only difference should be the extra newline character in the output. Regards, -- Rowan Tommins [IMSoP]