I would like to be able to type cast into custom objects. Currently in PHP
you can do the following:
$bar = 12345;
$foo = (string) $bar;

I would like to be able to do this:

$foo = (\My\FooObject) $bar;

A new static method will be available in all classes like this:

namespace My;

class FooObject {
    // ... normal class stuff ...

    public static function __cast($bar)
    {
        // Code here would be used to create a FooObject from the passed
variable
        // or throw error if passed variable is incompatible
    }
}

The default behavior, if the developer doesn't implement the __cast()
function would be to check that the object is of that type or a derivative
of that type.  I would like this mostly to make my code more predictable.

Thoughts?

Chris



On Wed, Nov 13, 2013 at 1:22 PM, Ken Snyder <[email protected]> wrote:

> Now you've piqued our interest... what is it you want to change?!
>
>
> On Tue, Nov 12, 2013 at 8:59 PM, Chris London <[email protected]> wrote:
>
>> I'm trying to create an extension to change some PHP behavior and I was
>> wondering if anyone on this group has any experience with that.  I've done
>> minor PHP extension programming but it's usually to add a new function and
>> not change existing behavior. If anyone has any info or could point me in
>> the right direction I'd greatly appreciate it. Thanks!
>>
>> Chris London
>>
>> _______________________________________________
>>
>> UPHPU mailing list
>> [email protected]
>> http://uphpu.org/mailman/listinfo/uphpu
>> IRC: #uphpu on irc.freenode.net
>>
>
>

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to