Nathan Rixham wrote:
concurred; I recently made a class that turn's all objects into XML; and
implented it in my __toString()'s :)
In that case rather than __toBool() __toInt() etc. it should really
support a magic __cast() method or similar.
This method would contain a single argument that represents the type
(e.g. a class name or a builtin type....
function __cast($type)
{
switch ($type)
{
case 'string':
return 'Foo';
case 'array':
return array('Foo');
case 'DomDocument':
// etc.
}
}
And if you did:
$foo = new MyClass;
$xml = (DomDocument)$foo;
It would return the result of __cast called with $type == 'DomDocument'.
That would be nice and generic.
I could see that being quite useful (tho' arguably, itmplementing a
cast() method is not that hard:
$xml = $foo->cast('DomDocument');
It's not as neat tho' :)
col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mandriva Linux Contributor [http://www.mandriva.com/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php