Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105157 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48629 invoked from network); 9 Apr 2019 10:35:38 -0000 Received: from unknown (HELO mail-lj1-f177.google.com) (209.85.208.177) by pb1.pair.com with SMTP; 9 Apr 2019 10:35:38 -0000 Received: by mail-lj1-f177.google.com with SMTP id q66so13531512ljq.7 for ; Tue, 09 Apr 2019 00:32:28 -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=Gwokd0LR9ErOjkd0ykRx4Uef5Hp1WOWRRBKcPU4729c=; b=npO/Np3ifjHItvwahwDhsyI8kRIBbQKyQynF7q52MUEAr7mA9t2MiWKKHmWNwwweuj L6QfrMGr3zZDaJ0K2bFlSgdYjBzfWBX41AtIPdFOpEPYpmAuRT86xu+nkQJR7LaiRNly s2eNnWv1TmgWwAjf1zlVTDNwtBvB9TzRglaTe9vQGayWkSdNEvKsBgbKGHqT0des/VBy ycKWkf2Hn21cYZCD4woJYBTFDlzF8DGxygUgfQmaT4CW18LrPRmIBdyjDZIIhsrkC9oo 0+RF7psTMfWwLfn5nr6VJITgmrMuQvNiVOes32QLi8uh+I+I11FeP2hSrsJjpzuuMlZq rTwA== 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=Gwokd0LR9ErOjkd0ykRx4Uef5Hp1WOWRRBKcPU4729c=; b=i6MaoLdxh9SWyoD7MWWDG84Eeq5GGthCkzp8NuTphyyEtSohmkm2EDfW/X7HnKknrW p/Y6KABgh9Cte7+HIcJoaH6KPR2zGWf0rQ5Tx+6yUUIJwWMIcUZkmpe7zokaMTgO4VeO 30bFIj/hxyJr0x36cIn/7NPZAo94T6QPJbBFOV/Va3xeosGfM5pdZ9gRJmu8hy3eZG8b VynHDNveRoR7uxcRR3ecRSlmdSO2mQwu82wdUPwrws/OKkY3gnC9sPnQNQbsSWXSH9sn rSJBLHn/Vkv2our2xL1YdFwCUD9gZrZgh03oFL8gGHeCUndCedHLdTFVY1kqNqYo2PkT m/4g== X-Gm-Message-State: APjAAAX+HgP9HQInIDR6SzItD+UuviItzep4z9lqHZvBYn2QLFJL2848 haSarfetr358MQE4ydPIV7XpD+4BDXNBERxIQw== X-Google-Smtp-Source: APXvYqxj0CpXa8mfil10ffcWeaV6B5K6tDHrTCqrT3ROQqSn/xSGJjK4NmNnh6NulrlJi2iWuBODEWf7NZfp7sM80dE= X-Received: by 2002:a2e:b01a:: with SMTP id y26mr1927725ljk.38.1554795147871; Tue, 09 Apr 2019 00:32:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 9 Apr 2019 09:32:16 +0200 Message-ID: To: Dan Ackroyd Cc: PHP internals , David Rodrigues , Claude Pache Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Nullable Casting From: guilliam.xavier@gmail.com (Guilliam Xavier) Dan Ackroyd wrote: > > I'm guessing you don't actually have ths function getIntOrNull() in > your code-base? To help me understand where this would be useful, > could you provide some 'real-world' code where this would be useful? Hello, thanks for digging in :) Here's a "real-world" situation I happened to come across (*NOTE: simplified for sanity*): vendor/bar/api/src/Dest.php (code we don't own): send(/* FIXME */ $source->getNumber(), $source->getName(), /* ... */); } } As you can see, it's actually pretty close to the RFC example; I'm not sure it's worth to add complexity... > But please can you post the actual use-case you _need_ this for. Or > possibly update the RFC with that example. Currently, imo, the RFC is > just presenting an alternative syntax for something that is not 100% > needed. You have a point, but all the current alternatives I can think of (namely: use a ternary (or an `if`), possibly with a temporary variable; write (and autoload) custom casting functions; or give up on strict typing) suffer one or more of the following downsides: - increased risk of mistakes - verbosity / more maintenance - performance overhead > I do kind of like the idea in the RFC, but I think it needs a better > argument for it. For your other points, I find that Claude Pache has given pretty good arguments in the meantime (thanks!) =) (By the way, I also thought about say, "nullable_intval()", "nullable_strval()" etc. but we're missing "arrayval()" and "objectval()"...) Best regards, -- Guilliam Xavier