Guido Contreras Woda wrote:

> 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

One of the biggest problems is that it's not always clear which
conversion should be used; consider, for instance,

  $obj1 + $obj2

where __toInt() as well as __toFloat() might make sense.

A possible solution would be to force the conversion with type casts,
but I don't see a real advantage in using

  (int) $obj1

over

  $obj1->toInt()

where the latter is a normal user defined method.

Another problem is that such automatic casting from objects to scalars
might obscure the code.

-- 
Christoph M. Becker



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

Reply via email to