Re: __asType()
| From: | Brad LaFountain | Date: | Tue, 06 May 2003 05:25:26 +0000 |
| Subject: | Re: __asType() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-1283@lists.php.net to get a copy of this message | ||
--- Sterling Hughes <sterling@bumblebury.com> wrote:
> On Mon, 2003-05-05 at 18:55, Brad LaFountain wrote:
> > 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.
> >
>
> Right, I understand how the engine works here. Extensions like
> SimpleXML should not be modifying opcodes, imho. Its not their job to
> change the language semantics.
Yeah but its necesarry if you want to implement what you were describing.
Unless they beef up the object api with something like...
class SimpleXML {
function __array($index) {
}
}
> > 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
>
> Yeah, that was my other solution. The problem is that requires an extra
> level of indirection, in cases with:
>
> <foo>
> <bar id="sterling">bam</bar>
> </foo>
>
> echo $doc->bar; // can't be done, this is an object with attributes
Yeah I knew I was missing something that you were asking because I knew you
understood what I was explaining.
again, a possible soultion could be another internal
class SimpleXML {
function __tostring() {
}
}
But where do we draw the line...
might as well add opperator overloading while your at some of this...
- Brad
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com