__asType()
| From: | Sterling Hughes | Date: | Mon, 05 May 2003 13:01:05 +0000 |
| Subject: | __asType() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-1271@lists.php.net to get a copy of this message | ||
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
<?xml version="1.0"?>
<name id="20">
<id type="age">30</id>
</name>
name.php
<?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