Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110596 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 49002 invoked from network); 16 Jun 2020 15:39:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Jun 2020 15:39:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C3A3180509 for ; Tue, 16 Jun 2020 07:25:24 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 ; Tue, 16 Jun 2020 07:25:23 -0700 (PDT) Received: by mail-lf1-f45.google.com with SMTP id d7so11850067lfi.12 for ; Tue, 16 Jun 2020 07:25:23 -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=7pKMqcLds/4qvtjteX+o74J7WH0mltbSkNZKGkMSs04=; b=dWRvreQFDpChPg64eDx0mBzLqkYbtAJ+2fyEPA82b+NTKzj9NgtWWEk0wQjA4kYavK 5gnqrBo+HIyfsNH9o6mKxDoSMj1hzy1t/cuETvkDBUroZDmJnNmKRgPdt3FAu5O6Qluc tIB4Y8fm+byC3WV9HFcwdEv3k5B5pMZB89VBidSplKYDK57qvtX4mYNj6REfHo4HPytT 1g5wR4QLx04n7bVfjP4omu7RRKGC1pjsmEvo8AS1y7Yk6ROc+TwCBhH0ZhqCf7uOp3bL 8WWjR/Th38lqJyOCDIY+Lgfr8MXdSjECNMrVacPpZ13WStRCrcFKK0VzGlS4NbP9kRFG kQyg== 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=7pKMqcLds/4qvtjteX+o74J7WH0mltbSkNZKGkMSs04=; b=H/11JNw3zXuFbi8gchopWuCbxUJ80R4XuRYWxzQvHFj9k0CEYTBF6I1NIdu3nFbopf KQqApGcMz8mXdTLAUXzvsrHISqu56awAe9J6WcchGhmyTTrjsNr/SfAJhwvvR/2Sjb0x vElrgtBnMNAJhrTGYBM9rLES/TgZU53elr7A89DrGqrT5foA6N1MOjrFhb83/ghH+5m2 JPgPwliHaxD+M+5zd7e3V2kKh6CX9yLmCrns9LXugPOnche8q+HmKWW4VjB7DiD7fVAN F+cjoYpok2p2B+NHvLPADlewXk3G8c1A5OP8ZYtFqNkAb4mAVOAM8f6XFotlt69d6KxW M1Cg== X-Gm-Message-State: AOAM533RLqmoRHSpd5eLP3cesuSPBLZxaTINR/6g5dvqpxsmek5iwaZ6 Dq2HaHc2guSB3Rwk4CXr96ixM++jFdnhcA7Fjmk= X-Google-Smtp-Source: ABdhPJz/LMCFEl8CYetB/V0jzYWDH1SS+qQ3+8I+So3KhW+YafrAe1iiwP9YiV+j+ltEGgOmNl4YY+yV4z6XrPP5Bg4= X-Received: by 2002:a19:8389:: with SMTP id f131mr1860676lfd.16.1592317519290; Tue, 16 Jun 2020 07:25:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 16 Jun 2020 17:25:06 +0300 Message-ID: To: Jesse Rushlow Cc: Dan Ackroyd , =?UTF-8?B?TcOhdMOpIEtvY3Npcw==?= , "G. P. B." , PHP Internals List Content-Type: multipart/alternative; boundary="0000000000001b652805a83450f1" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Allow void return type for constructors/destructors From: benas.molis.iml@gmail.com (Benas IML) --0000000000001b652805a83450f1 Content-Type: text/plain; charset="UTF-8" Exactly :) Personally, I have numerous times caught myself declaring constructors `: void` too. I would love to have everything consistent and all methods to have a return type. Although, I do understand that not everybody agrees with me and that's why this RFC isn't planning to ever force people to use `void` return type. As I have said before: some might use it, some might not, but both cases are valid and allowed :) Best regards, Benas On Tue, Jun 16, 2020, 5:11 PM Jesse Rushlow wrote: > From a PHP developer's POV - when writing a class or refactoring one. I > have to catch myself all the time trying to declare ": void" on the > constructor. It's mostly a habit from doing so with the other methods in > the class. I lean in favor of being able to declare a void return type on a > constructor, but only for the aforementioned reason. I have never ran into > a use case where I've questioned what the return type is for a constructor. > Although I could see newcomers to PHP / Development in general ponder that > thought. > > Thanks, > Jesse Rushlow > > On Tue, Jun 16, 2020 at 8:59 AM Dan Ackroyd > wrote: > >> G.P.B. wrote: >> > Seems like a no brainer and a good addition. :) >> >> For situations where stuff is simple, 'no brainers' are okay. >> For situations where everything is horribly convoluted, 'no brainers' >> are often bad. >> >> Benas IML wrote: >> > even though no return type means mixed|void >> >> Not quite. >> >> No return type is _treated as_ 'mixed|void' in some circumstances >> particularly signature checks during inheritance. That's not quite the >> same as 'meaning' the same. >> >> > What I meant, was that since no return type means `mixed|void`, >> > you can't do the following: >> >> I'm actually not sure exactly what you're trying to say there, but I >> think pasting the text I reference whenever trying to think about LSP >> might be useful... >> >> "PHP allows contravariance (aka type widening) for parameter types to >> obey the LSP principle. A subclass may use a 'wider' aka less specific >> type in place of the inherited type for a parameter." >> >> "PHP allows covariance (aka type narrowing) for return types to obey >> the LSP principle. A subclass may use a 'narrower' aka more specific >> type in place of the inherited type for a function return." >> >> > I am proposing to allow void return type for constructors/destructors. >> >> Constructors in PHP have multiple issues that are 'surprising'. I'm >> not sure that fixing only a small part of how they are surprising, >> improves PHP drastically. >> >> Also...I really wish we already had null as a usable type, as most of >> the uses of void are slightly inaccurate. >> >> The meaning of void and null are: >> >> void - this function doesn't return a value >> null - this function returns a value that has no information in it. >> >> Presumably you want to be able to specify void as the return type to >> make it be easier to detect errors in code like the example you >> provided. >> >> It seems that making a rule for whichever static analyzer you're >> using, that errors on any assigning of a value from a __construct >> call, would achieve that, without touching a part of PHP that is full >> of edge cases. >> >> To be clear, I'm not sure if I am in favour or against the RFC. The >> real problem is that constructors just don't fit into how we think >> about normal functions is PHP, because of the magic that goes on >> around them and so both void and null as return types would be a >> little bit incorrect. >> >> cheers >> Dan >> Ack >> >> >> >> Some example functions using those two return types. >> >> function this_is_void_return(): void { >> exit(0); >> } >> >> function this_is_also_void_return(): void { >> throw new Exception("no usuable return value"); >> } >> >> function this_is_also_also_void_return(): void { >> while (1) { >> echo "Hello world\n"; >> } >> } >> >> function this_is_null_return(): null { >> // deliberately empty. >> } >> >> // This code is fine. >> var_dump(this_is_null_return()); >> >> // This code is never going to execute the var_dump, which >> // might indicate an error. >> var_dump(this_is_void_return()); >> var_dump(this_is_also_void_return()); >> var_dump(this_is_also_also_void_return()); >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> --0000000000001b652805a83450f1--