Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110690 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 76615 invoked from network); 21 Jun 2020 02:28:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Jun 2020 02:28:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E41BA180211 for ; Sat, 20 Jun 2020 18:15:18 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS31103 84.19.160.0/19 X-Spam-Virus: No X-Envelope-From: Received: from mail.toneristzuen.de (mail.toneristzuen.de [84.19.169.162]) by php-smtp4.php.net (Postfix) with ESMTP for ; Sat, 20 Jun 2020 18:15:17 -0700 (PDT) Received: from maniacmansion.fritz.box (ppp-188-174-57-131.dynamic.mnet-online.de [188.174.57.131]) by mail.toneristzuen.de (Postfix) with ESMTPSA id 3E6354B5CC; Sun, 21 Jun 2020 03:15:16 +0200 (CEST) Message-ID: To: Jesse Rushlow , Dan Ackroyd Cc: Gabriel Caruso , PHP Internals Date: Sun, 21 Jun 2020 03:15:14 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Make `always true` SPL methods return void From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Thu, 2020-06-18 at 23:17 -0400, Jesse Rushlow wrote: > * Disclaimer - I have not thoroughly reviewed the bug report or PR > mentioned. > > From a PHP developers perspective, if I was calling a method that > returned true. I would automatically assume that the method is > capable of returning the inverse of that as well. The fact that it doesn't today, might change tomorrow. If it now returns true this can be changed with less BC issues later. Also returning true allows chaining with `&&`, which void wont't. Also to the specific case: The specific case is about this: $test = new \SplStack(); var_dump( $test->push(1)); Assume we add a SplLimitedStack with a ore-defined size. There push might return false if the stack is full. By having "all" push() methods following the same pattern, generic code can work on either the same way. Thus looking at a single method isn't good for a design, but one should look at a class of types. (and then it might be a decision that push always returns void and errors should be reported via exception) Just to point out that there is a bit more than "oh, this always returns true" Also another side note: We have echo and print. print purposely always returns true for being usable in expression chains. johannes