Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:1280 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28024 invoked from network); 5 May 2003 22:55:16 -0000 Received: from unknown (HELO web9605.mail.yahoo.com) (216.136.129.184) by pb1.pair.com with SMTP; 5 May 2003 22:55:16 -0000 Message-ID: <20030505225515.60779.qmail@web9605.mail.yahoo.com> Received: from [129.44.9.18] by web9605.mail.yahoo.com via HTTP; Mon, 05 May 2003 15:55:15 PDT Date: Mon, 5 May 2003 15:55:15 -0700 (PDT) To: Sterling Hughes Cc: internals@lists.php.net In-Reply-To: <1052139665.11377.339.camel@hasele> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [PHP-DEV] __asType() From: rodif_bl@yahoo.com (Brad LaFountain) References: <1052139665.11377.339.camel@hasele> Yes both of these are possible, Z2 only. Marcus has provided an example how to overried the opcodes from z2 and use them effectivly. He overrides 3 opcodes to get the array functionality. taken from php_spl.c ZEND_EXECUTE_HOOK(ZEND_FETCH_DIM_R); taken from spl_array.c.c ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FETCH_DIM_R) { if (cur_object_is_simple_xml()) { return_attribute_from_object(); NEXT_OPCODE(); } ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_FETCH_DIM_R); } if you look what ZEND_EXECUTE_HOOK does it replaces zends opcodes with its own handlers. Now the down side of this is if different extensions keep doing this over and over, it could slow down array handling. AND Your other type of access is simple object overloading or you can setup zvals before hand. if you use overloading it might look something like this //Imagine this was in c class Simple_XML_Node { function __get($name) { $this->$name = get_node_from_data($this->raw_xml, $name); return $this->$name; } function get_attr($attribute) { return $this->whatever; } } otherwise you would have already set up the xml attributes at xml parse time I hope you know what i mean. Talk a look at marcus spl extension, he did some neat stuff there with the opcom overloading. http://marcus-boerger.de/php/ext/spl/ - Brad --- Sterling Hughes wrote: > Hi, > > When developing my SimpleXML extension, I've come to a situation where I > want to have the ability (internally), to convert my object to a base > type, when requested. I need this when both attributes and xml tags are > identical within the same context, ie: > > data.xml > > > 30 > > > name.php > $n = new Simple_XML('data.xml'); > echo $n->id; > ?> > > I'd like the ability to provide two modes of access for the object, > array and object. So, one could do: > > $n['id']; // attr > > And > > $n->id; // node > > However, barring that, I'd like the ability to simply cast the object as > a base type, essentially :: > > echo $n->id; > echo $n->id->get_attr('type'); > > And have them both work. Are either of these a possibility? > > -Sterling > > -- > "Reductionists like to take things apart. The rest of us are > just trying to get it together." > - Larry Wall, Programming Perl, 3rd Edition > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com