How to Force a Method Call on a Property or Method of an Object in PHP?

Posted by Noah Goodrich on Stack Overflow See other posts from Stack Overflow or by Noah Goodrich
Published on 2010-01-07T02:41:34Z Indexed on 2010/03/12 1:17 UTC
Read the original article Hit count: 483

Filed under:
|
|
|

In my View (using Zend_View so the the view is an object), I make calls to object properties and methods to populate the template like so:

<?= $this->user->name ?> // Outputs John Doe
<br/>
<?= $this->user->getCompany()->name ?> // Outputs Acme
<br/>
<?= $this->method() ?> // Outputs foobar

If I make it so that all property requests (like for 'user') go through __get() is there any way that I can catch the subsequent calls so that I can force a method call on the final outputted value? For example so that I could do automatic escaping of output.

As I see it right now, I either have to escape the input as it goes into the database or use compiled templates like Smarty does, or switch to assigning every variable to the View object so that it has direct control to force escaping before outputting the data.

© Stack Overflow or respective owner

Related posts about mvc

Related posts about xss