# toString() in SimpleXML?

- Thread: https://externals.io/message/15016
- Original archive: https://news-web.php.net/php.internals/15016
- Started by Leendert Brouwer on 2005-02-14T12:23:44+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #15016 — Leendert Brouwer — 2005-02-14T12:23:44+00:00

URL: https://externals.io/message/15016#15016

Hi,

I have a feature request. Maybe it would be a good idea to have a 
toString() or perhaps nodeValue() method in SimpleXML's SimpleXMLElement 
class? It might make it more obvious that the element is still a 
SimpleXMLElement object when you want to actually use it (when you print 
it, the value automagically casts to a string internally, so users might 
think that it will be casted to a string when you directly access it 
without a specified property/method, which is not the case). I know that 
the docs say that you should cast it to a string when you want to do a 
comparison, but apart from that just being an example, maybe my 
suggestion is a more obvious one to notice?

regards,

Leendert

---

## #15029 — Marcus Boerger — 2005-02-16T20:10:46+00:00

URL: https://externals.io/message/15016#15029 · In reply to: #15016

Hello Leendert,

  having a function __toString() would interfere with the mapping ideas of
SimpleXML. However it is there internally so you simply do one of the
following:
php -r '$x=SimpleXML_load_string("<?xml version=\"1.0\"?><root>blablabla</root>"); echo $x, "\n"; var_dump((string)$x);'

regards
marcus

further questions please to general@php.net

Monday, February 14, 2005, 1:23:44 PM, you wrote:

> Hi,

> I have a feature request. Maybe it would be a good idea to have a 
> toString() or perhaps nodeValue() method in SimpleXML's SimpleXMLElement 
> class? It might make it more obvious that the element is still a 
> SimpleXMLElement object when you want to actually use it (when you print 
> it, the value automagically casts to a string internally, so users might 
> think that it will be casted to a string when you directly access it 
> without a specified property/method, which is not the case). I know that 
> the docs say that you should cast it to a string when you want to do a 
> comparison, but apart from that just being an example, maybe my 
> suggestion is a more obvious one to notice?

> regards,

> Leendert




-- 
Best regards,
 Marcus                            mailto:helly@php.net
