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


Cheers!

Reply via email to