Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58173 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27149 invoked from network); 27 Feb 2012 19:05:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2012 19:05:25 -0000 X-Host-Fingerprint: 208.107.21.52 host-52-21-107-208.midco.net Date: Mon, 27 Feb 2012 14:05:23 -0500 Received: from [208.107.21.52] ([208.107.21.52:1759] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/14-40985-3F3DB4F4 for ; Mon, 27 Feb 2012 14:05:23 -0500 Message-ID: <67.14.40985.3F3DB4F4@pb1.pair.com> To: internals@lists.php.net References: <6d4a9f99bc550c8c673b32cbccc52444.squirrel@www.l-i-e.com> User-Agent: slrn/pre1.0.0-18 (Linux) X-Posted-By: 208.107.21.52 Subject: Re: [PHP-DEV] Object Casting - An Alternative to Type Hinting From: weierophinney@php.net (Matthew Weier O'Phinney) On 2012-02-27, "Richard Lynch" wrote: > On Mon, February 27, 2012 9:20 am, Anthony Ferrara wrote: > > > I have to say that no matter how much a luv my OOP, turning every > > > built-in type into an Object is just a Bad Idea... > > > > > > It's a form of bloat on RAM and CPU with minimal added value, imho. > > > Re-read what I had written. I never said to turn every built-in type > > into an object. In fact, what I was talking about was keeping and > > preserving the base types as-is. All that I was proposing was adding > > the ability to cast from and to the primitives. That way you could > > silently convert back and forth as needed (transparently when > > possible). > > > > I apologize that my brevity has been misconstrued. > > You are certainly free, even with the tools available in PHP, to > "wrap" an object around integers, strings, and so on. > > There may even be occasions where I think that would be a Good Idea (tm). > > What I object to is building such a facility into core PHP, because: > > 1) You can already do it in userland, and I believe that's where it > belongs. Actually, you can't. The point of Anthony's proposal is that while we _can_ wrap scalar types in objects, that fails for the instances where you need to perform operations with them. This is why he's proposing the ability to cast to and from these "scalar objects", and have calls in the engine that would do the casting on-demand. > 2) It unnecessarily [see 1] complicates core PHP, whose major > strengths that drive its success includes its simplicity. The flip-side of the argument is that if many developers are doing code like this over and over again: public function setNumber($number) { if (!is_scalar($number)) { throw new InvalidArgumentException('Need a number!'); } $this->number = (int) $number; } ... then it may be time for the language to make this easier. (And just because _you_ or a subset of developers on internals don't write code this way does not mean a _majority_ of developers do not.) -- Matthew Weier O'Phinney Project Lead | matthew@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc