Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60558 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98401 invoked from network); 13 May 2012 23:40:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 May 2012 23:40:42 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.131 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.131 smtp131.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.131] ([67.192.241.131:33768] helo=smtp131.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DF/CA-16338-97640BF4 for ; Sun, 13 May 2012 19:40:41 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp29.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id 11414398278; Sun, 13 May 2012 19:40:38 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp29.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id BC66639822C; Sun, 13 May 2012 19:40:37 -0400 (EDT) Message-ID: <4FB04675.6000307@sugarcrm.com> Date: Sun, 13 May 2012 16:40:37 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Seva Lapsha CC: "internals@lists.php.net" References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Custom Casting From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > Please be kind to review and comment my proposal for custom casting in PHP > (or let me know if a similar proposal was already discussed). > > http://pastebin.com/sPb0i8U6 I think there's an issue with this idea. As far as I understand, what is proposed is kind of cast-constructor paradigm. However, the result of (ClassName)$var would be expected to be an object of type ClassName. That is, however, not what cast() returns - it returns integer $var. Since there's no way for foo(ClassName $var) to know where $var came from, the result of $var = (ClassName)$var; is just a simple integer and foo() would reject it since it's not an object of type ClassName. Of course, you could just create this instead: class PositiveInteger { private $i; function __construct($i) { if(intval($i) < 1) $i = 1; $this->i = $i; } function intval() { return $this->i; } } function foo(PositiveInteger $i) { return 2*sqrt($i->intval()); } and then: foo(new PositiveInteger(42)); But this is doable right now, even if sounds a bit of overkill for me. I wouldn't mind also having (int)$i done with some magic methods, as proposed in RFCs you mentioned. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227