On 2012-02-27, "Richard Lynch" <c...@l-i-e.com> 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            | matt...@zend.com
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to