Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58561 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43268 invoked from network); 4 Mar 2012 02:48:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Mar 2012 02:48:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=lists@rotorised.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=lists@rotorised.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain rotorised.com from 203.88.115.241 cause and error) X-PHP-List-Original-Sender: lists@rotorised.com X-Host-Fingerprint: 203.88.115.241 ironport1-mx.cbr1.mail-filtering.com.au Received: from [203.88.115.241] ([203.88.115.241:40288] helo=ironport1-mx.cbr1.mail-filtering.com.au) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 36/D4-12048-108D25F4 for ; Sat, 03 Mar 2012 21:48:34 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AucFALPWUk+va78L/2dsb2JhbAAoGoMJsj+BfQEBBScRQBELGAkWDwkDAgECAUUTCAEBF4drDCm4Do07gyIEmx+KMYJ1 X-IronPort-AV: E=Sophos;i="4.73,526,1325422800"; d="scan'208";a="598033567" Received: from ju001lcs02.dfw.the-server.net.au (HELO ju001lcs02.dfw.the-server.com.au) ([175.107.191.11]) by ironport1-mta.cbr1.mail-filtering.com.au with ESMTP; 04 Mar 2012 13:48:15 +1100 Received: from [124.191.162.147] (helo=[192.168.0.12]) by ju001lcs02.dfw.the-server.com.au with esmtpa (Exim 4.69) (envelope-from ) id 1S41Ub-002Zql-Ct for internals@lists.php.net; Sun, 04 Mar 2012 13:48:14 +1100 Message-ID: <4F52D7FA.6040501@rotorised.com> Date: Sun, 04 Mar 2012 12:48:26 +1000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: internals@lists.php.net References: <4F52D301.5060101@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC - discussion] Object Scalar Type Casting Magic Methods From: lists@rotorised.com (Ryan McCue) Anthony Ferrara wrote: >> 2. Having separate methods is probably not the best idea. It may lead to >> implementation having inconsistent conversions between types, such as floats >> and integers, etc. or having conversions to float but not int and getting >> very hard to debug errors because of that. Also may lead to conversion be >> context-dependent and create very confusing results. > > Well, as you know that was part of my original proposal ( > https://wiki.php.net/rfc/object_cast_magic ). However, after talking > with a few core devs about it, it seemed that separate methods are the > preferred solution, as the single method requires a big switch (which > isn't as clean, and will promote returning improper types, Floats when > an int was asked for, etc)... For that reason, it seems more fragile > to maintain, so I agreed with splitting it to multiple methods. I definitely agree, separate methods are much easier to deal with and should be the way to go here. If you use a single method for all the casts, you'll probably end up recreating separate methods anyway (i.e. `case 'int': return $this->toInt();` ) which seems silly to me. -- Ryan McCue