Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75685 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64741 invoked from network); 18 Jul 2014 07:44:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jul 2014 07:44:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=simonsimcity@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=simonsimcity@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.172 as permitted sender) X-PHP-List-Original-Sender: simonsimcity@gmail.com X-Host-Fingerprint: 74.125.82.172 mail-we0-f172.google.com Received: from [74.125.82.172] ([74.125.82.172:52683] helo=mail-we0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/51-54879-F30D8C35 for ; Fri, 18 Jul 2014 03:44:00 -0400 Received: by mail-we0-f172.google.com with SMTP id x48so4195951wes.31 for ; Fri, 18 Jul 2014 00:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=djvzZAt0ukwUnIwDVpdzo4GPUAyDiAMOnuWxg5fKvxc=; b=moM/oTiuEZvo3Q4zAsCN8mr5MrZift+XTHWUE1CaPDWuDsdG43OXy/Qj1n2PglsglU LdVLD2Ya70M7CBtihbzNZDP6HwqK5MOL4Hs1NEt0QBAPT4X8i+vAmBqp83F1VW17J84x xLWi7fvyrkW0rl96hMQ9mvmEjoh9Zl5AzQIYG934OV72T6Md6JhYnJkXRHGz+Khc9aPR wGHYpJcMPGOk/795c9X9FhftFguUzYzbmwdDrEyvHBB9RWDG99v+TEc954leKV1BaVxY ctPJ9nnXpwerwBD1xotsibY0idtDFeuXmZ5FMVuH7feD0FxoHoxrkvnLJYzM2J4QK8/t AxRA== MIME-Version: 1.0 X-Received: by 10.180.10.138 with SMTP id i10mr4689714wib.81.1405669436564; Fri, 18 Jul 2014 00:43:56 -0700 (PDT) Received: by 10.194.222.134 with HTTP; Fri, 18 Jul 2014 00:43:56 -0700 (PDT) In-Reply-To: References: Date: Fri, 18 Jul 2014 09:43:56 +0200 Message-ID: To: Theodore Brown Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: simonsimcity@gmail.com (Simon Schick) On Fri, Jul 18, 2014 at 7:02 AM, Theodore Brown wrote: >> Since I am very much in favour of scalar type hints, I've updated the >> patch to master and made some minor improvements, and I am re-opening >> the RFC with the intent to try and get it into PHP 5.7. > > First of all, this is my first reply on PHP Internals so I hope I am doing it right. :) > > Thank you very much Andrea for reviving this RFC - I'm really looking forward to using > something like this in the next version of PHP to more easily define interfaces and > catch unintended errors in my code. > > However, something I feel it is important to consider is not just how scalar type > annotations fit into the history of PHP, but how they fit with the way type annotations > are currently used and where the language is going in the future. > > A recurring comment I've heard in the discussion for this RFC is that strict type hints > aren't "the PHP way." However, current type hints for classes, arrays, and callables > work exactly in this way - they do not allow nulls, no casting is performed, and an > invalid type results in a fatal error. If scalar annotations are introduced, many PHP > developers (myself included) would naturally expect them to behave in the same way. > > Another concern I have is in regard to the future. I'm looking forward to the > possibility of specifying nullable types in a future version of PHP (see Levi Morrison's "Declaring Nullable Types" RFC: http://wiki.php.net/rfc/nullable_typehints). If the > nullable types RFC is accepted, it would be highly disconcerting if scalar type > annotations allowed null values regardless of whether a nullable marker is specified. > > I don't think that optional strict type annotations will take away from PHP's dynamic > nature - they will instead be a valuable feature used in places where it is necessary > to strictly validate a parameter's type - this is especially important to ensuring > stability and accuracy in the large PHP applications it is my job to maintain. > > The RFC has already been updated to make boolean type annotations strict. Doesn't it > make sense to treat the other scalar types in the same way? Perhaps a future RFC could > propose a second (also optional) syntax to specify type annotations which perform casts. > However, only having cast-based annotations for scalar types would be a mistake, IMHO. > > -- > > Theodore Brown > > A PHP developer interested in the language's future > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > Hi, all First of all, thanks for all your time, you put into this thread! I really am looking forward for a way, all can live with, because this topic has followed the PHP community since the release of PHP 5.1, since the introduction of type hinting for arrays (http://php.net/manual/en/language.oop5.typehinting.php). On an archive for this mailinglist I found threads that are going back to 2005 (http://marc.info/?l=php-internals&m=112397232722668&w=2) - Here's a list of all messages found: http://marc.info/?l=php-internals&s=type+hinting&q=b I've been one of the most active contributors to a thread back in 2012 - not the one giving most productive feedback, but the one giving the most feedback ... (I later saw a statistic of who posted the most mails to the mailinglist within the months of discussion) What I see, we're again stuck with mainly three different opinions, as Paul Biggar pointed out in his post - and he tried to find a solution back then. I would suggest that anyone should read this mail - if you want, read the thread - I haven't had the time for now..: http://marc.info/?l=php-internals&m=124653792412529&w=2 In every round we took this topic, there have been new RFCs added ... I don't know if there will be a solution, and my personal favorite is the way, proposed in this RFC here. No casting for the values, just more a validation - a lossy validation. The main reason for this proposal is, that mostly every input to your application will be a string. If it now is a file, a value from the database, the GET and POST parameters, a CURL response - nearly anything. I don't think it makes sense to first cast them before you can use them. I agree, that it feels wrong to have a method, accepting (string)"123abc" and casting it to (int)123 for internal usage, but it also feels wrong to not let the input (string)"123" pass as a parameter to a method accepting integer. This would lead us to casting (f.e. substr("string", (int)$var) ), what again would be like accept anything ($var = "abc"). I also saw some complaining about that older code may will not work when introducing something here. As of what I think, this should be implemented as an extension to the language as it is now. Old code should be able to run as it is. You may will get a problem when your old code is using a library, that you want to update and the library is using the new syntax ;) Thanks for reading. Bye Simon