Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88764 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83409 invoked from network); 13 Oct 2015 10:42:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Oct 2015 10:42:08 -0000 Authentication-Results: pb1.pair.com header.from=mike.php.net@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=mike.php.net@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: mike.php.net@gmail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:34082] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C0/91-04042-FFFDC165 for ; Tue, 13 Oct 2015 06:42:08 -0400 Received: by wicgb1 with SMTP id gb1so83515480wic.1 for ; Tue, 13 Oct 2015 03:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=YXWd+o+xaj2YnabJq9OEoaUdOpW+2H2j9SdLvYSrVgo=; b=TmchkcPwdCnFjnFhciRrnECNITs6UJfAI2BkAOtL5YggtAUzfvY2WlA+JFSgt+J3wS dO+7DtyDGOG9he2qap+bzC8/dhdvZRY8mRsMQP1e64MSoZw8MJizos+lkQOH8St5m/nR 2L9Tvjqba0MG1W/j2Wbe2ZtE7qCbnus1hYK4/O1VDukDHGKtHg1H2rtkmotFpu9psi8Z oQvsnD+QNT+RTdzEE3uIBqu9O6/37+Zt/l1AK+kmffu9fXzGzyP+uplIfsKql0YLk+4P f/KSzeTJb/hJiFFzQo/MbihifssXJT2QsZv5ml+mW9NwHArlbHsnAukQn1hGldvToCRP 6GOg== X-Received: by 10.180.102.226 with SMTP id fr2mr21402648wib.3.1444732924657; Tue, 13 Oct 2015 03:42:04 -0700 (PDT) Received: from [192.168.2.120] (89-104-28-113.customer.bnet.at. [89.104.28.113]) by smtp.googlemail.com with ESMTPSA id wt4sm2839489wjb.29.2015.10.13.03.42.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Oct 2015 03:42:03 -0700 (PDT) Sender: Michael Wallner To: Andrea Faulds , internals@lists.php.net References: <5C.21.16518.AA80C165@pb1.pair.com> Message-ID: <561CDFFA.8040207@php.net> Date: Tue, 13 Oct 2015 12:42:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <5C.21.16518.AA80C165@pb1.pair.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Scalar type hints and scalar type name aliases cause confuson From: mike@php.net (Michael Wallner) On 12/10/15 21:23, Andrea Faulds wrote: > Hi, > > As PHP 7 currently is, if you write this: > > public function foo(): integer { > return 12; > } > $bar = foo(); > > you'll get the following error: > > Fatal error: Uncaught TypeError: Return value of foo() must be an > instance of integer, integer returned > > Similarly, if you were to write this: > > public function foo(): boolean { > return true; > } > $bar = $foo(); > > you'd get this: > > Fatal error: Uncaught TypeError: Return value of foo() must be an > instance of boolean, boolean returned > ... > Alongside or instead of that, though, we can do two other things to make > this situation better. > > First, we could make type error messages use 'int' and 'bool'. This > feels somewhat wrong to me since integer and Boolean are the proper > English names for the types. But we do use the short names in some other > places, like var_dump, so this isn't so bad. This way, we get this > slightly clearer error: > > Fatal error: Uncaught TypeError: Return value of foo() must be an > instance of integer, int returned > > Second, we could add a helpful note to the TypeError message when the > type hint is for a class named 'integer' or 'boolean' and the value > passed was an integer or Boolean, respectively. My patch (based on > Anthony's original) for the earlier Scalar Type Hinting with Cast RFC > did this. This would make things even clearer: > > Fatal error: Uncaught TypeError: Return value of foo() must be an > instance of integer, int returned (did you mean to use the type hint > 'int'?) > > Even if we can't reserve the names, I hope we can do the two other > suggestions in time for release. Additionally, we could say "instance of class ...". -- Regards, Mike