Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60585 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14782 invoked from network); 14 May 2012 18:44:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 May 2012 18:44:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=seva.lapsha@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=seva.lapsha@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.170 as permitted sender) X-PHP-List-Original-Sender: seva.lapsha@gmail.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:57623] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/81-03088-58251BF4 for ; Mon, 14 May 2012 14:44:21 -0400 Received: by yenm2 with SMTP id m2so3771562yen.29 for ; Mon, 14 May 2012 11:44:18 -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=TN5KKCh6iRHqPa2GaMMsVwrJBsIlUWL/Cwdm7baQEUg=; b=mDgCMz9oAj57mMKL/DbuKVXjwTORZZm8NyOVtQDob2Hh8ds7lSbMoEmGLdErcUuWtj 2cx2PT4kUma4BR0m3FPEe5f/zErQcRLK6NLKfvWJ+RAAFjnBKjtoyQX0l0oq0b2cETol ELl3kf9tiz93aihWpQLUR0V6wJQ2mmoepoix1KvnGod0go0LXBVjeVBEZZ+JMK846H1g c4Bknr75TWYbF4+2Fo8LOxyhOFEFEwrnx4s2ewJtY7uWcX1W9FG8SNaAplnNnaaz8FEI UkhKlfVf8pcIif6OB1KRJS8a2AIVZZ5gsw8QjsC23CXsjHytelFT+TmclU9LQ81n8m/w yYeQ== MIME-Version: 1.0 Received: by 10.50.11.198 with SMTP id s6mr5025482igb.36.1337021058050; Mon, 14 May 2012 11:44:18 -0700 (PDT) Received: by 10.231.241.199 with HTTP; Mon, 14 May 2012 11:44:18 -0700 (PDT) In-Reply-To: <4FB14EBF.7070404@sugarcrm.com> References: <4FB04675.6000307@sugarcrm.com> <4FB14EBF.7070404@sugarcrm.com> Date: Mon, 14 May 2012 14:44:18 -0400 Message-ID: To: Stas Malyshev Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=e89a8f6465f538ec1504c003798f Subject: Re: [PHP-DEV] [RFC] Custom Casting From: seva.lapsha@gmail.com (Seva Lapsha) --e89a8f6465f538ec1504c003798f Content-Type: text/plain; charset=ISO-8859-1 Thanks. On Mon, May 14, 2012 at 2:28 PM, Stas Malyshev wrote: > Hi! > > > Not quite. The proposed is a syntactic sugar which is thought to handle > > any transformation of a value, not necessarily or limited to type or > > class conversion. It is of course possible to limit the usage to just > > that, with any user defined convention or "best practice". In fact it's > > pretty distinct from primitive casting, I just had in mind that reusing > > the casting syntax could be an advantage due to similarity of the > behavior. > > > > In simple words the statements of /$var = (ClassName)$var/ or > > /function(ClassName $var){}/ would not be read as "Cast to", but "Cast > > with". > > But currently this syntax already means "convert value to a value of > this type" in the first case and "allow only value of this type" in the > second case. Overloading this syntax IMHO will lead to a singificant > confusion, and you would not know what exactly foo(ClassName $var) means > - would it only accept ClassName or would it instead convert $var using > transformation ClassName? > My point is exactly that these are different things with different results. > > > The example suggestion with wrapping the value in an object just for > > handling value validation/sanitization is not just overkill, but also is > > excess, since there is no any need to have the value wrapped after the > > function input processing. In fact, the closest construct to the > > mentioned is: > > > > function foo(/* to be casted with PositiveInteger */ $i) { > > $i = PositiveInteger::cast($i); > > return 2*sqrt($i); > > } > > Yes, I know. These are two different approaches - the difference is > where the casting responsibility lies. You can define a type > PositiveInteger and assign it the responsibility or you can define that > each client is responsible for its own casting, however it wants to do > it. I understood that you were going for the former. > > I think the idea of custom casting might be useful, but overloading > existing syntax with it will lead to serious confusion. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > --e89a8f6465f538ec1504c003798f--