How do entry elements render a default string but also return an object at the same time? So this is more of a PHP question than a Craft question, but the only example I can offer is one I've seen in Craft.
{{ craft.entries.id(4).one() }}
Returns a simple string like: &quot;About Page&quot;
{{ dump(craft.entries.id(4).one()) }}
Returns the entire element object.
From a PHP perspective, how does this work? Or where can I find out more about this practice?
It's a tricky thing to look up online and tracing through Craft's codebase hasn't offered much insight for a novice like me.
It's the __toString() magic method:

The __toString() method allows a class to decide how it will react
when it is treated like a string.

https://www.php.net/manual/en/language.oop5.magic.php#object.tostring