Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58745 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10920 invoked from network); 7 Mar 2012 16:58:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Mar 2012 16:58:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.170 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 209.85.160.170 mail-gy0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:36436] helo=mail-gy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 78/A4-15180-6B3975F4 for ; Wed, 07 Mar 2012 11:58:30 -0500 Received: by ghbg2 with SMTP id g2so3415424ghb.29 for ; Wed, 07 Mar 2012 08:58:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=DvoYagLdEooSc37IiYPcIqlYAAHBjUXwHR6cbK694Rg=; b=P5c9UG3yogpcGsSqKTEbCXDqI3QnpgqE02KgYgSULSIOajxtoBQsolMrEI4pJWfEoK yTzD2IfXv/jLcxrOmcEDDKh72jfI3IUkFCHrc+e0Q6Wbbb4L6MDiW/PCBFtxBhUatcUc 7rZcmtGKDBzz8F0M8DcvQFsPJb5lGbqJnNLq7OEsQzYiMMCzNuGfP8T4coQJVJ0H4VRP k42t0OHKkAzcm7k2kXin/ouoz5Nskkh1sMNksLRqXGklQycpkxlO9z6KcSJ4gFlf0pM6 XDLGL5CYjFMlC2BYCtWnzUCxYLRgtiQ7MzncQ+UcBDSfGRqQ93Xsp42Q7pVPfwwHXPmY 8e+Q== Received: by 10.236.76.198 with SMTP id b46mr5534068yhe.25.1331139507572; Wed, 07 Mar 2012 08:58:27 -0800 (PST) MIME-Version: 1.0 Received: by 10.146.144.35 with HTTP; Wed, 7 Mar 2012 08:58:06 -0800 (PST) In-Reply-To: <4F578D52.4080704@akbkhome.com> References: <4F578D52.4080704@akbkhome.com> Date: Wed, 7 Mar 2012 17:58:06 +0100 Message-ID: To: Alan Knowles Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf300fb3a77ed12304baaa11d3 Subject: Re: [PHP-DEV] Scalar Type Hinting From: linepogl@gmail.com (Lazare Inepologlou) --20cf300fb3a77ed12304baaa11d3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable > You could try some kind of stricter casting. Where odd conversions between array/object <-> bool/int/float/string do not work on parameter casting .. but then you end up with two types of casting ... I have used in depth the casting operators of C#, which are incredibly flexible and powerful, and they are based on this exact idea. In C#, there are two types of casting: implicit and explicit. The first is used for trivial conversions and the later for the "odd" ones. It is possible to classify PHP's casts into these two categories: int to string: implicit int to float: implicit int to object: explicit int to array: explicit ... Once this classification is done, the code becomes much more sane. Examples= : function test_float( float test ) { ... } test_float( 1.0 ); // ok test_float( 1 ); // implicit int to float cast, ok function test_array( array test ) { ... } test_array( array() ); // ok test_array( 1 ); // no implicit int to array cast, error! test_array( (array)1 ); // explicit int to array cast, ok I deliberately avoided using Anthony's cast-like syntax, because it does not fit nicely here. Calling a function may cause an implicit cast, but it will never do an explicit one. Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel 2012/3/7 Alan Knowles > Comment in-line below... > > On Wednesday, March 07, 2012 07:10 AM, Simon Schick wrote: > >> Hi,: >> >> It got quite around that because we have some RFCs to this where the >> functionality seems to be defined as the people thought it should be. >> Otherwise they can raise their hands and write a mail that they want to >> update the RFC - but as there's no one doing that, I think we're quite >> close to what we wanted. >> >> Take a look at it and feel free to add your ideas in this thread. >> https://wiki.php.net/rfc/parameter_type_casting_hints >> https://wiki.php.net/rfc/object_cast_to_types >> > > Been watching this for a while, got slightly interested in the parameter > casting thing, but then ran a little test > http://www.roojs.com/examples/types.php > > Casting on PHP may help the code inside the function, but the result is > some weird and wonderful magic for the calling code, not to mention that > the docs for (int) casting say the behavior may change, don't expect it t= o > work like that forever.. > > You could try some kind of stricter casting. Where odd conversions betwee= n > array/object <-> bool/int/float/string do not work on parameter casting .= . > but then you end up with two types of casting ... > > Anyway, will go back to lurking for a while.. > > Regards > Alan > > >> Bye >> Simon >> >> 2012/3/6 Kris Craig >> >> Wow no offense, but your timing is terrible, Raymond! We've been going >>> back and forth on this for the past couple weeks now, though the >>> discussion >>> has quieted for the moment. >>> >>> I would suggest you go through some of the recent posts on Internals. >>> Right now there basically is no solid consensus on this issue, though >>> some >>> of us have been working to change that. But as it stands now, I'm not >>> aware of any plans to introduce expanded typing of any kind in the >>> foreseeable future. And even if we did, I highly doubt it would happen >>> before PHP 6. >>> >>> --Kris >>> >>> >>> On Mon, Mar 5, 2012 at 6:20 PM, Raymond Irving >>> wrote: >>> >>> Hello, >>>> >>>> I came across some info on the web that states that scalar type hintin= g >>>> >>> was >>> >>>> added to the PHP trunk but it did not make it's way into 5.4 because o= f >>>> objections from the community. Will it ever make it's way into 5.5? >>>> >>>> I know PHP is considered to be a weak typed language but it should als= o >>>> >>> be >>> >>>> about freedom. Freedom for a PHP developer to choose to use scalar typ= e >>>> hinting whenever he/she sees the need. >>>> >>>> >>>> Best regards, >>>> __ >>>> Raymond >>>> >>>> > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --20cf300fb3a77ed12304baaa11d3--