Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:12976 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17782 invoked by uid 1010); 25 Sep 2004 04:52:26 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 17734 invoked from network); 25 Sep 2004 04:52:25 -0000 Received: from unknown (HELO took.shire) (68.122.184.4) by pb1.pair.com with SMTP; 25 Sep 2004 04:52:25 -0000 Received: (qmail 45538 invoked by uid 1001); 25 Sep 2004 05:16:38 -0000 Date: Sat, 25 Sep 2004 05:16:37 +0000 To: internals@lists.php.net Message-ID: <20040925051637.GD84277@bagend.shire> Mail-Followup-To: internals@lists.php.net References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i Subject: Re: [PHP-DEV] Ideas on hooking into the object cast handler From: curt@php.net (Curt Zirzow) * Thus wrote Robert Silva: > I'm working on creating object wrappers for native php types. With ZE2 and > the cast_object object handler, I am able to "unbox" the objects to their > native php types with simple casts, but as ZE2 currently stands, (to my > knowledge at least) there is no way to hook into the (object)native_type > cast. Currently, when you cast a native value to an object using > (object)$native_val, it calls convert_to_object which simply converts the > native type to an array. I was hoping some of you more familiar with the ZE > than I had some ideas of how it may be modified to allow an extension to > hook into the convert_to_object function. Looked around for some > implementation of an extension registering a callback inside the engine but > couldn't find any examples. Here is a userland example of what I am trying > to accomplish: > > $intObj = new PInt32(5); // Int object wrapper > $phpInt = (int)$intObj; // Calls the cast_object handler for the PInt32 obj I was actually thinking about this the other day, my idea was to force an object declaration to tell everyone that it can be casted, so ZE2 will define all the different type of interfaces: /* ZE2 defined interface represented in php */ interface Castable { function __toString(); function __toInt(); function __toFloat(); function __toArray(); function __toObject($objname); /* questionable */ } Then if a object wishes to be converted to a paticular type it would simply implement the interface: class Foo implements Castable { ... function __toString() { return "I am a string"; } ...all the rest of the interface definitions } The questionable toObject() would provide the possiblities of something like: $newObj = (OtherObject) $FooObject; But, iirc, the above will probably involve a lot of rewriting of the parsing. Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid!