Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92659 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23085 invoked from network); 23 Apr 2016 16:41:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Apr 2016 16:41:18 -0000 Authentication-Results: pb1.pair.com header.from=quim@kalpe.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=quim@kalpe.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kalpe.com from 209.85.213.173 cause and error) X-PHP-List-Original-Sender: quim@kalpe.com X-Host-Fingerprint: 209.85.213.173 mail-ig0-f173.google.com Received: from [209.85.213.173] ([209.85.213.173:36157] helo=mail-ig0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DC/12-07837-DA5AB175 for ; Sat, 23 Apr 2016 12:41:18 -0400 Received: by mail-ig0-f173.google.com with SMTP id f1so42292892igr.1 for ; Sat, 23 Apr 2016 09:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kalpe-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=yGKYKXyVmL2nLBgQ7lkpCNeMSL16onHgH9biBwRURLM=; b=ikVG/D/7FOtvPWvCG1g/KYatHmxPT5u8zJu9Gwb5uKiQe02OSyQ6YnEd1THeKI1gq4 1WpqHnaSbASPaTbHzgUCX4DMHSmApFr1XmCZONTeoh51WxG7HPyw8SGGgE7Lc8q91HKH HcyFchRzpl9CMYwuJHrnN5b0giYxJs+m5H626W9brrW2FGGeZwXktCLX7nVa4qBXJf9U bAyBw676XpR560vSu4hYuIbSfy6/EcXeSvY82mRrrIZ8wfpdhZQ9pIypHf+cFzZObAYY iSR7R/+XKxRFeBxz3Z/muZ2hlE6CW2ZNTHFPlO4u3EiijwKvuV+sWuJOYAifob41qu6r YTkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=yGKYKXyVmL2nLBgQ7lkpCNeMSL16onHgH9biBwRURLM=; b=QkgEFXbZrXve+ATCXHMW/TaCU3cpYefAyASQ+qUWDS1FvWTHYi2OPzep9Y+fSt2Enz Y5iU73sJJDNWqwWhquNji6lMiTW042iJC/qwMFKA07C4Y0VmLdbKSRMwg30evLLcSE7o IAHhLAU9SCuqTUaJiPXGrk/hIHX2abrhzRgy/A2DBjWW9XIq9k2ZkgAtfs5yAtA+arlq xacps5GB7weYUe3tyPNn8Q9VjI8xunTMcntaZo6UvyTuh4cZRD/+rNPG3sVStlRLjFaS 6jP7fjj4qfB21X68xdsIy+8fwrmTfW3/E0jfYWyIasIb5fvew7aUiMQCXiHIpyrxbIha bTDA== X-Gm-Message-State: AOPr4FV7vbZYPUGb5tbjJELBH0a043z8eOU+i1d5veHGD0zvm6dtTL8PBFosOF+SAMw0TycOxT9oEN/UKT+5rw== X-Received: by 10.50.98.195 with SMTP id ek3mr3429548igb.85.1461429675538; Sat, 23 Apr 2016 09:41:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.220.194 with HTTP; Sat, 23 Apr 2016 09:40:55 -0700 (PDT) In-Reply-To: <571B6AF6.5030001@fleshgrinder.com> References: <57192F87.4080902@fleshgrinder.com> <571B6AF6.5030001@fleshgrinder.com> Date: Sat, 23 Apr 2016 18:40:55 +0200 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=bcaec501620dacddc60531299c86 Subject: Re: [PHP-DEV] [RFC] Nullable Types From: quim@kalpe.com (Quim Calpe) --bcaec501620dacddc60531299c86 Content-Type: text/plain; charset=UTF-8 Hi Richard, On Sat, Apr 23, 2016 at 2:30 PM, Fleshgrinder wrote: > On 4/22/2016 11:42 AM, Quim Calpe wrote: > > IMHO, the point of Optional types is the intention, if you get an > > Option from a method, you have to deal with a None branch. Of course > > you can just unwrap and go on, but it's a developer decision to do that, > > not an oversight as using a Foo|null (or ?Foo) as an object directly. > > > > IMOH, the point of ?T is the intention, if you get a null from a method, > you have to deal with a null branch. Of course you can just ignore it > and go on, but it's a developer decision to do that, not an oversight as > using a Option as an object directly. > > Sorry, but this works in both directions. The problem is not null, the > problem is that there is no system that warns you (e.g. a compiler) > about the missing null check. I think that Ceylon solved this problem > extremely nicely without the introduction of something special. > Of course, this works in both directions, but I see a value in Option types: function getByEmail(string $email) : ?User {} $user = getByEmail("foo@bar.com"); echo $user->getName(); I neglect the nullable return but works at first , all fine... .. a week later... "Warning: Call to a member function getName() on null" With Option type: function getByEmail(string $email) : Option[User] {} $user = getByEmail("foo@bar.com"); echo $user->getName(); IDE could warn me and It crashes right away, an option type must be unwrapped so I get the "intention" immediately :) > > function fn(): ?T {} > > $x = fn(); > if (is $x T) {} > else {} > > Not doing as above is a compiler error in Ceylon. However, I already > wrote multiple times that there are already statical code analysis tools > available that can find exactly such things in your code. One just needs > to use them. > That's really nice > > -- > Richard "Fleshgrinder" Fussenegger > > Option types are nice, but I feel we are going a bit off-topic. Option types work better with other niceties like for comprehensions, pattern matching... And I don't see PHP going that route in the near future, and probably It's not okay for PHP to go that route... Nullable return types is a better fit for PHP, null has been in the language from the beginning, I agree here --bcaec501620dacddc60531299c86--