Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86270 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81829 invoked from network); 16 May 2015 21:13:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 May 2015 21:13:09 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.170 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.170 mail-pd0-f170.google.com Received: from [209.85.192.170] ([209.85.192.170:33801] helo=mail-pd0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5A/0F-14891-4E2B7555 for ; Sat, 16 May 2015 17:13:08 -0400 Received: by pdeq5 with SMTP id q5so78896204pde.1 for ; Sat, 16 May 2015 14:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=fbr1IOn1CYIXoVlWGLvihg/WWdUFTbYeFPVzw+TrkYk=; b=DMawJL/8Q4uil1++Ymy8v+jLqtZXrzgfc6n+4lmXsGDCO/l+yBfcIFSsS/VEBi/X4D kZ0sA172D4QjmQEEBXw4kVUMZVpClK517PDynHGGkx8F82jtauK5PHsT7D3AKu3dh7hn QcsfATDveBitGqP0AedyWcxkGAykvu1YpZgb+sBAnW6gYkEwvpvot3WkVYUjvhrOqlMy lphHDqb1tpxlJ3TRViOxLIlOl8ihPfu0QGhTx3+SWOM2+/Y0vFXlDPnr5iC3ynpO8jbZ FNjIXnZPtR2ul64w7G5cviYC3DDiCeOLDiz0mfBURS99eRug3LeGfZqGFzAFnRLCmQcg /3/w== X-Received: by 10.70.51.67 with SMTP id i3mr30497373pdo.145.1431810785027; Sat, 16 May 2015 14:13:05 -0700 (PDT) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id mt11sm5589154pbc.20.2015.05.16.14.13.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 May 2015 14:13:04 -0700 (PDT) Message-ID: <5557B2DC.1080007@gmail.com> Date: Sat, 16 May 2015 14:13:00 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Guido Contreras Woda , internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Proposal: interfaces for object to scalar type casting From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > So, what do you think of a set of interfaces that allow userland objects to > be used as scalar types? > > Some simple examples in PHP here: > https://gist.github.com/guiwoda/5d16c8fb97d29e476d20 We already have CastToString, it's __toString. I'm not sure we need a named interface for that, as checking for the method would be basically the same, and practically I do not see anybody wanting to type against such type (i.e. you'd do foo(int $a) but not foo(CastToInt $a)). As for others, we in fact have cast_object handler for the objects, so extensions can already do that. Giving user functions access to it would be not hard, though I'm not sure it won't complicate some things. But I think if enough people need it, enabling full user-space access to cast_object should not be a problem. Definitely needs a good RFC though with good convincing examples of use cases. -- Stas Malyshev smalyshev@gmail.com