Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58592 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99949 invoked from network); 5 Mar 2012 08:15:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Mar 2012 08:15:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=simonsimcity@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=simonsimcity@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: simonsimcity@googlemail.com X-Host-Fingerprint: 209.85.214.170 mail-tul01m020-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:61968] helo=mail-tul01m020-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/71-25873-C36745F4 for ; Mon, 05 Mar 2012 03:15:56 -0500 Received: by obbwd1 with SMTP id wd1so4552951obb.29 for ; Mon, 05 Mar 2012 00:15:53 -0800 (PST) Received-SPF: pass (google.com: domain of simonsimcity@googlemail.com designates 10.60.11.40 as permitted sender) client-ip=10.60.11.40; Authentication-Results: mr.google.com; spf=pass (google.com: domain of simonsimcity@googlemail.com designates 10.60.11.40 as permitted sender) smtp.mail=simonsimcity@googlemail.com; dkim=pass header.i=simonsimcity@googlemail.com Received: from mr.google.com ([10.60.11.40]) by 10.60.11.40 with SMTP id n8mr7224840oeb.61.1330935353545 (num_hops = 1); Mon, 05 Mar 2012 00:15:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=N8B3AjU60MSsd6v8b7FjXIG7VHVjcn8vLd0dMq0zZ3A=; b=ColWj9ZHG7Vh4qQZp0aZ+STQWFz2RvWrd+lnHztCsSNBSOQJbZx3M5qOCivD5K8gM9 gBGErsOcqnWfWv2eYG+OP1pguDFoTR8HKoJ6BH5TbEVpJxdWhIiKenfT5CoaORK8s/ua 8b93dbWx8bOoSNolD8Pm2i5Vi5xg4uyM8zLsMi8+m3MptKi2+jK5JWDct5PNez2lrag0 80Hp4QmfV5QFWnoJPK0ZnvPIdqvMzujEBXhhkrvw1UIpctPNWUrnIC6UDc+uASwzedy+ eP3mWKR8r3EN7VH+sqDlWPc7L2mpzi/LuUqd2BRQUUxY0TcIb3qBG6ipE3jAXWaVseML KWwQ== MIME-Version: 1.0 Received: by 10.60.11.40 with SMTP id n8mr6357789oeb.61.1330935353424; Mon, 05 Mar 2012 00:15:53 -0800 (PST) Received: by 10.60.56.101 with HTTP; Mon, 5 Mar 2012 00:15:53 -0800 (PST) In-Reply-To: References: Date: Mon, 5 Mar 2012 09:15:53 +0100 Message-ID: To: Lazare Inepologlou Cc: Paul Dragoonis , Anthony Ferrara , internals@lists.php.net Content-Type: multipart/alternative; boundary=e89a8fb204d4f5bb4804ba7a8899 Subject: Re: [PHP-DEV] [RFC - Discussion] Parameter Type Casting Hints From: simonsimcity@googlemail.com (Simon Schick) --e89a8fb204d4f5bb4804ba7a8899 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, Lazare This is something not obvious, at least for me, and should be handled in the function itself. Here it would be better to update the function *add()* that you could also pass mixed and it will try to generate a *DateInterval *out of that or whatever. But that's another RFC. Type-juggling applies just to weak-types like string, int, float and boolean. I don't like to have this for resource, array or class excepted they are compatible to each other (like array and SplFixedArray, SplObjectStorage, ArrayIterator, ...) If you have to do something special to get the expected type (like creating a new object) type-juggling would not be the good-way to go. Bye Simon 2012/3/4 Lazare Inepologlou > > > > I wouldn't want people to put class typehints in there such as > > > function foo( (SomeClass) $foo) > > > > Why not? I would definitely like something like that, in the future. Here > is an example: > > class DateTime { > ... > public function add( (DateInterval) $interval ) { ... } > ... > } > $date =3D new DateTime; > $date->add( 'P3D' ); // string to DateInterval casting > $date->add( 3600 ); // int (seconds) to DateInterval casting > > Personally, I find this to be much closer to free type-juggling PHP style > than the current implementation with type hints ( > http://www.php.net/manual/en/datetime.add.php). > > [ Actually, I would prefer even type hints to work like this. Check if th= e > passed argument if of the correct type and, if not, try to cast it. Failu= re > to do so will lead to the E_RECOVERABLE_ERROR as today. ] > > > Lazare INEPOLOGLOU > Ing=C3=A9nieur Logiciel > > > 2012/3/4 Paul Dragoonis > > > Can you make sure that only scalar or array casts can be done? > > > > I wouldn't want people to put class typehints in there such as > > function foo( (SomeClass) $foo) > > > > - Paul. > > > > On Sun, Mar 4, 2012 at 1:28 AM, Anthony Ferrara > > wrote: > > > Hey all, > > > > > > I've drafted an RFC for the Parameter type casting hint proposal that > > > I posted to before. Attached to the RFC is a patch that's proposed > > > for inclusion in core for functionality (it doesn't include news > > > entries, or documentation, or any of the other steps that would be > > > needed prior to commit). > > > > > > https://wiki.php.net/rfc/parameter_type_casting_hints > > > > > > Please provide feedback here on the implementation and RFC topics. > > > > > > Thanks, > > > > > > Anthony > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > --e89a8fb204d4f5bb4804ba7a8899--