Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93277 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78795 invoked from network); 12 May 2016 14:29:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 May 2016 14:29:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wm0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:38170] helo=mail-wm0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 12/BF-28272-D2394375 for ; Thu, 12 May 2016 10:29:01 -0400 Received: by mail-wm0-f49.google.com with SMTP id g17so139228658wme.1 for ; Thu, 12 May 2016 07:29:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=tXTMzdNJJD0gYNvMTrtWTWjalvtDutQbODcFPbmIzuo=; b=njk5wJcnzPMze8ZensnCQSZ9j2QxizD7+0NO42QkBM0dHlFm1xxshH8mx6+u5ENisQ S6FfYeR3IqGQfKuAgoFByTqtWI7R+9jsO8jPYJFSFEOio+VV3wVucPW3lkBoW1mmnkh3 u70isIwD5/Ris20Kb+qrZPNFhdCn6Y/Jsf846dO5wzQ7+KwfibOX4yNXZJ7M/8WQONqW rR1JJkM0L8d8n7kc2D7kR7/AK3hTvaITZeVnYb8bnYwUOh2DrhJMMJLjLPO4FwQCoWLH 2YVrgJT5on/6E0UqirnfuVwVLbP1CDyKRoQ/iUiuUcegJ6KiuvIhkdrFe61G4beSBZLy UT8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=tXTMzdNJJD0gYNvMTrtWTWjalvtDutQbODcFPbmIzuo=; b=A8E1NtrcLr/b9YS07qQg6Q3Q682wcw4NguKmpIgafoFVU3QNEmMlo3IwVgF3101/q9 pb32xE6vhrV0JBxmYu7jiDOuHkkbq37Dc3+N2BOQUPZOFHTYwHUkLns8U6V7diimIRUl vdREzrha/7fG5//sC/ReVRX26vcerCMjOGVm3u/XADLq6LGkGW75OhtW1e0hiicQMsY1 Y2/FJsAy3bNBWeRlxAFjQGTdF/VLpAoAcO3PUuFlw7KWyeK+d3mgvMvUMNlkYQiD1hoW d7Y4icdmvb6Y4QV91n3fT7NUIxhp869xtu7WAgocwOTnYn9acR9dZMQ6zgSrLNfDrV2o 6A/g== X-Gm-Message-State: AOPr4FUELh8g6WMK8vMSEtIuSZjgODA9TW47gJmjChKTetNkQFYmIq6muMFRNHhpvCOW+A== X-Received: by 10.28.125.138 with SMTP id y132mr10982756wmc.90.1463063338838; Thu, 12 May 2016 07:28:58 -0700 (PDT) Received: from [192.168.0.98] ([93.188.182.58]) by smtp.gmail.com with ESMTPSA id c16sm14105848wme.16.2016.05.12.07.28.57 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 12 May 2016 07:28:58 -0700 (PDT) To: internals@lists.php.net References: <573232DB.8030209@lsces.co.uk> <573308EC.70502@lsces.co.uk> <57346ABE.1070509@lsces.co.uk> <6dabc30a-7b4b-d71c-5a64-4005fd622a2e@gmail.com> <57348922.4060101@lsces.co.uk> Message-ID: <12345f19-d387-4984-63db-2ee677e34a7a@gmail.com> Date: Thu, 12 May 2016 15:26:27 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <57348922.4060101@lsces.co.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: [RFC][VOTE] Nullable Types From: rowan.collins@gmail.com (Rowan Collins) On 12/05/2016 14:46, Lester Caine wrote: > The key element *I* of cause am miss reading is the (Bar ...) which is a > type hint. That will not exist in any of the code prior to ? and that is > the key to what is being discussed. No type hint ... no change? > > If someone 'improves' a third party library by adding type hints then > this is were the using code needs to be checked? Correct. It should be no different from what can be done with existing type hints - if I change a library you were using from "function foo($bar)" to "function foo(Bar $bar)", it's possible you were passing a different object in and will now get an error. If my library was always expecting Bar objects anyway, I'm arguably doing you a favour by forcing you to fix a long-standing bug where you passed the wrong thing. The way I like to think about type hints in PHP is sugar for assertions at the top of the function: function foo(Bar $bar) { #... } is roughly equivalent to: funtion foo($bar) { assert($bar instanceOf Bar); #... } The new syntax is just a different sugar, so that: function foo(?Bar $bar) { #... } is roughly equivalent to: funtion foo($bar) { assert(is_null($bar) || $bar instanceOf Bar); #... } If the language didn't support typehints at all, I could add assertions like that in my library, and cause basically the same behaviour if you call my functions the wrong way. [Strictly, in PHP 7, it's more like "if ( ! CHECK ) { throw new TypeError; }" rather than assert(), but the default result is the same.] Regards, -- Rowan Collins [IMSoP]