Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107687 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 66974 invoked from network); 25 Oct 2019 04:44:44 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 25 Oct 2019 04:44:44 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 7D0DE2D1FF5 for ; Thu, 24 Oct 2019 19:31:17 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-ua1-x941.google.com (mail-ua1-x941.google.com [IPv6:2607:f8b0:4864:20::941]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Thu, 24 Oct 2019 19:31:17 -0700 (PDT) Received: by mail-ua1-x941.google.com with SMTP id j5so140712uak.12 for ; Thu, 24 Oct 2019 19:31:17 -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=ATx4gqeGZ3E0QnnPP5nktRrVmarva0CXyFTgecJjgbA=; b=h+EaTIT/A9KlvyFIPcVUHjXyzPqfX/TVA4IBWUtthpNQocaT2c6fsfR2j3drIgIlIc hYdI6NhjodWbYBphFhmO88grraVPZS3OocZ9N/9LD9cdN5wPGFjHY+IJJwLM0gTRB0g5 xwYOKC3aAprpRV+snvqNo6SpsUGqpbnHlEtLLDjh/K7IaH3cuYprIvkC9FgKqg4B3ciA p/WrBlqXa3+JNubww++bm7lmVXJ+JLplsyO4qSROz1pQx4XT3FKhLR4/hveOiKI0Jipn 4ih5UWVYrM5r+xfYn5MLDy+CKAslLMeZaKhxnNfLcuhTGM5T4qOTuVmTvEqIZqn1XJYZ cKlg== 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=ATx4gqeGZ3E0QnnPP5nktRrVmarva0CXyFTgecJjgbA=; b=UKDDTuz0Slv9f8TLq+ACR3yFJTzLTF/3M8Fpc6bOFCMRXr2NjtY5Xl1Wq4SXETRit6 fIgA2JCf5on66HCET9Q1dv829BwO5BEgMIMp/3vys11i0ijcu/Npcpl3RNSYOix4STFK GCaKH2uNSDlvUFa+Q7TzPZpXwGGBPosOCleQ/p6jgmTSrLCBpEqN/A5lTPhaTIQpsZAS 37VODgE1i/XLnTujdTs5tVWg9fBha0LP/BGVprAJ1eXvjqC52DHqBO9AvDdNGLR26CAT g0U9zCjW5iU4Qu8vslR6wz5ITqW1xlIaNP0i8rvj34/Dy46sLECxuHRK80iIaH4NnAoC qMXA== X-Gm-Message-State: APjAAAXiZWqSelePhAAsHzUfSv+qBL7TbjNJo5t4P4fhvfYp3QekVVuO SrvaW4qPJA6jDKSUlQFSik7tnXB0zDboEEyhHMo= X-Google-Smtp-Source: APXvYqy9b9+Bb7U/05HjUuArG8rym3lXkqF8hZHLN8pOggS2Z8lq4aqIl1A6xBZ1CKLN0X4Uqw3IQK6A9lgtQM4wscU= X-Received: by 2002:ab0:7304:: with SMTP id v4mr468454uao.0.1571970676416; Thu, 24 Oct 2019 19:31:16 -0700 (PDT) MIME-Version: 1.0 References: <5db21f54.1c69fb81.eda99.d428SMTPIN_ADDED_MISSING@mx.google.com> <09AB755E-4A05-4D19-8276-BFD658D92EED@newclarity.net> In-Reply-To: <09AB755E-4A05-4D19-8276-BFD658D92EED@newclarity.net> Date: Thu, 24 Oct 2019 22:31:04 -0400 Message-ID: To: Mike Schinkel Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000c3e6a10595b2f133" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] anti-coalescing-operator From: dohpaz@gmail.com (Ken Stanley) --000000000000c3e6a10595b2f133 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Oct 24, 2019 at 8:54 PM Mike Schinkel wrote: > On Oct 24, 2019, at 6:49 PM, Ken Stanley wrote: > I would be keen to see the more expressive techniques that retain the > succinctness of having a not-null coalescing operator. > > > > When I read your first example, I immediately thought I would handle your > example in this way: > > $user->setFName( $_SERVER[ 'fname' ] ?? null ); > > $user->setLName( $_SERVER[ 'lname' ] ?? null ); > > $user->setMName( $_SERVER[ 'mname' ] ?? null ); > > $user->setPhone( $_SERVER[ 'phone' ] ?? null ); > > $user->setEmail( $_SERVER[ 'email' ] ?? null ); > > > Admittedly it does not require the functionality of your proposed > operator, and it delegates the null handling to the set*() methods, but i= t > is more succinct and does not require duplicating `$_SERVER[ '*' ]`, so > it would be a winner for me. > > The problem here is that null values may or may not be valid inputs for the setters. Assuming for one moment that the setters do allow null, what does that mean for the underlying model? Is null to mean that it=E2=80=99s under= ? Or is null just another possible value? Using !?? to only call a setter if there is a non-null value is very important in many circumstances - my original example was to illustrate a succinct way to implement a REST PATCH HTTP request, where only fields with values get updated - in other words, you don=E2=80=99t want to set other fi= elds to null because you want to retain their original values; not overwrite them. Overwriting values with null is a valid use case, but not for this operator (not necessarily). Null means nothing, no value, or better: not answered. This is distinctly different than =E2=80=98=E2=80=99, false, or 0. Those are explicit response= s to a question. Null Just means no data. > I also do not mind putting more effort into writing functions if it means > less effort required to call the functions. But maybe that is just me? > > But if you don=E2=80=99t have to, then why would you? I=E2=80=99m all for c= larity and expressiveness. But I=E2=80=99m also for simplicity and being as succinct a= s practically possible. > Your 2nd example was more compelling for me, but Sara's nullsafe calls RF= C > uses a syntax that is more clear and obvious to me. > > I am a Symfony developer, and as such I like to utilize annotations (bear with me). They have a ParamConverter annotation that can automatically look up an entity based on the type hint given to a controller action. If the parameter is null able, I may need to add an if condition to look up a sane default value when the parameter comes through as null. It would be much more succinct (and less error prone) to be able to say something like /** * @ParamConverter(name=3D=E2=80=9Capplication=E2=80=9D, ...) */ public function myAction(Request $request, Application $application) { $user =3D $application->getUser() !?? $this->getUser(); // ... do something with user, without worrying about it being null. } > Is there a 3rd or 4th use-case you have that are unlike the first two? > > I will let you know when I think of them. I totally understand how much easier it is for others to conceptualize with good examples. I want to be concise and relevant at the same time, and that=E2=80=99s actually pretty difficult. :-) > -Mike > > > > -- "Do not go gentle into that good night. Rage, rage against the dying of the light." =E2=80=94 Dylan Thomas --000000000000c3e6a10595b2f133--