On Wed, May 13, 2015 at 11:16 AM, Guido Contreras Woda <guiw...@gmail.com> wrote:
> Hello everyone! > > Multiple frameworks and libraries define interfaces or objects that wrap > around some scalar value and add behavior, the most common case being > arrays and Collection / Hash[Set|List] objects. Although this objects > benefit from the possibility of having behavior themselves, sometimes the > implementation is outside our project scope (an external dependency) and > interaction between this object and other blocks of code that expect scalar > types usually needs to be controlled by the user, which adds the necessity > for adapters or some sort of mediator. > > Now that we have the ability to hint return types, a common interface could > be built that, given an object that implements it, lets userland code use > this object as if it were the scalar type it is wrapping. Unboxing the > object is pretty easy, and I wouldn't go as far as proposing interfaces for > rebuilding the object itself (not now, at least). > > 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 > > I like the idea of supporting more __toType methods than just __toString. It would certainly make certain things in life a bit easier to manage. For now, I know I've abused __toString() and done things like (int)(string)$obj to get the Int value out of it. > > Cheers! >