how is it nette can echo its forms, which are objects

3 years ago

mikeb
Member | 30
+
0
-

this may be more a php question and showing my ignorance: I'm trying to understand the magic of nette – how is it we can create a form, treat it as an object and then just echo it?

$form = new Form;
$form->addText('name', 'Name:')
echo $form; // <-- why does this not break??

I know it renders using the default renderer by can't understand how and where this becomes a string, or doesn't get an error like ‘object cannot be converted to a string..’ etc
where's the magic hidden? can you point me to some classes and methods that achieve this?

Thanks
Mike

3 years ago

David Matějka
Moderator | 5936
+
0
-

There is __toString method on Form class, see php doc

3 years ago

mikeb
Member | 30
+
0
-

i didn't know about __toString – thanks, I'll follow that through