Re: Proposal: interfaces for object to scalar type casting

From: Date: Sat, 16 May 2015 21:13:00 +0000
Subject: Re: Proposal: interfaces for object to scalar type casting
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-86270@lists.php.net to get a copy of this message
Hi! > 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 We already have CastToString, it's __toString. I'm not sure we need a named interface for that, as checking for the method would be basically the same, and practically I do not see anybody wanting to type against such type (i.e. you'd do foo(int $a) but not foo(CastToInt $a)). As for others, we in fact have cast_object handler for the objects, so extensions can already do that. Giving user functions access to it would be not hard, though I'm not sure it won't complicate some things. But I think if enough people need it, enabling full user-space access to cast_object should not be a problem. Definitely needs a good RFC though with good convincing examples of use cases. -- Stas Malyshev smalyshev@gmail.com

« previous php.internals (#86270) next »