Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105322 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6528 invoked from network); 21 Apr 2019 17:18:15 -0000 Received: from unknown (HELO mail-it1-f172.google.com) (209.85.166.172) by pb1.pair.com with SMTP; 21 Apr 2019 17:18:15 -0000 Received: by mail-it1-f172.google.com with SMTP id z17so14193046itc.1 for ; Sun, 21 Apr 2019 07:18:09 -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=m8NBn2gu8laUd317sMjHgQ5wogxiXHstmcVW0WDW+dE=; b=ItlfdLhRjht4TksmxI9M++BaoVH3LYrV8wTR0e0tbrgpU1cfAEj3v2Xq2UbcO/x3FY jjh3RaOS1flKRWdXv8oTfzRzAKe5nNR7/9vLZty4OdziYiD8qNW+03Rvvvc2DA6hnOJl bgo7JY+vjKA9Gu7AV/2LJ4tYPd392hlRnV0ykDpPGxKil3Bsw3aKK3p/xr3StvYW7jWK p5eOnivg2FXLt3InWfe35EaybzcqlYCcurzVgk4iMb8ji5mals8o0aB4rNSxnmOYsxT9 HFcvfPN8Fp9fAFxvO5PKouymRl4o8B4Iel1fc2ZoPhKGzoGOraommdtmybce10xILdvo fjyw== 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=m8NBn2gu8laUd317sMjHgQ5wogxiXHstmcVW0WDW+dE=; b=MITR4rlt6LI+IjDHWduLAvl+Z9oU5muV6VwgiQBxdMU3KoM03pX+K0JbcnUnIByNHX qs4eqG5YW9akHCh1l2XqGOJcoDveDf2QfnotbJjEdgukQzRpl8hyDqjXrUeuSKyhvv3g VuON5VM9hv6ANqbexsfJhtasZ2lT8do8WOWoGwJCbpnK+dhuXAacZjozetJzQicbGfFx S3vI798QwdPVrqjE5hqE6pzJfUZsX9usz0r3KlgIFpXh/Bh0AgQ1Jloh3d8rLNjuu/fl HEBuFmfLR6dtDZ4HD8d8GmjUOfHQhVai4WnMi2l/Jj9pwBGbTL8rGrOzFgnNWEX/Xmkc 89+Q== X-Gm-Message-State: APjAAAXd+eCi9gDH00ScjY7HOo6Ajh7eaZ35wSuqp378KPnQjZvZQ5vD rny1ohBGr1zAnp3/OBp/qZgp5rVnGQfnc3mNPWA= X-Google-Smtp-Source: APXvYqzX96AqQivIScyiXTvJyhvPhjf+H+P/Wudj9ZETqQgfV52nx9WHyVghk6nLo0gwr1myHacDWpQk3ooYQMngbkM= X-Received: by 2002:a02:cbda:: with SMTP id u26mr10381750jaq.7.1555856289387; Sun, 21 Apr 2019 07:18:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 21 Apr 2019 11:17:57 -0300 Message-ID: To: Guilliam Xavier Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000735c0205870b05f6" Subject: Re: [RFC] Nullable Casting From: david.proweb@gmail.com (David Rodrigues) --000000000000735c0205870b05f6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Discussion topic: - Not 100% needed: is the same that says "nullable typehint is not 100% need because we can just check in time". This argument has no sense, once that PHP supports nullable casting for parameters typehint, and the nullable casting is just a way to fit the argument to parameter typehint that is already possible, but very hacky ($x !=3D=3D null ? (string) $x : n= ull vs. (?string) $x). - What about e.g. nullable_intval()? intval() is a PHP 4 feature that could be replaced in 99% of cases by (int) cast. So nullable_intval() make no sense once that probabily it will be never used (except it (?int) will not be implemented, but if nullable_intval() could be, so is better (?int) instead). - Fallible Casting: it should works exactly as current castings, but with possibility to be null if it is already null. For instance: (int) "string" currently will be int (0), by this way, so (?int) "string" should be int (0) too. The nullable casting will ONLY return NULL if the subject is NULL, exclusively in this case. So it will affects only (int) null that currently is int (0). So (?int) null will be null. Same for falsy values: (int) '' is currently int (0), so (?int) '' will be int (0) also. - Alternative syntax (null|int): very ugly, no? :P Maybe on future it could be valid for multicasting eg. (string|int|float) $x, but this is subject to another topic. - A cast where you can't be sure of what you'll get back: you will have the same sure that currently you have with (int) $x, with exception that nullable values are more explicit because "if $x is null, then you will get null with 100% of sure". For cases like: (int) 'string', (int) '123string' and (int) 'string123' what you got? (It is already supported by PHP): Answer: int (0), int (123) and int (0), respectively. Em dom, 21 de abr de 2019 =C3=A0s 06:19, Guilliam Xavier < guilliam.xavier@gmail.com> escreveu: > On Sat, Apr 6, 2019 at 9:52 AM Guilliam Xavier > wrote: > > > > Hello internals, > > > > David and I would like to open the discussion on our joint RFC: > > > > https://wiki.php.net/rfc/nullable-casting > > > > Mainly, it would enable to use e.g. `(?int)$x` besides `(int)$x`. > > > > We are looking forward to your feedback [...] > > > > Thank you, > > Hello again internals, > > Thanks everyone for your valuable feedback. I have updated the RFC > with a new Discussion section to [try to] summarize the various > arguments raised in this thread. > > -- > Guilliam Xavier > --=20 David Rodrigues --000000000000735c0205870b05f6--