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.
> 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
-Sterling
--
Good judgement comes from experience, and experience comes from
bad judgement.
- Fred Brooks