johnsmith153 Posted December 2, 2010 Share Posted December 2, 2010 This probably doesn't matter much, but I am using a 'Display' class for final output to the browser. The class will display the obvious HTML header and then display either the full site or the mobile site. It also displays the CSS / JS (which is previously selected in the page-specific controller code as there are variations based on server-side checks). Basically it is the ONLY class that actually needs to send anything to the browser. When I begin output and echo inside the class, that is the end of the script - there is no more server-side code to execute. If I shouldn;t echo inside the class, is it that bad to do so? Quote Link to comment https://forums.phpfreaks.com/topic/220509-oop-echo-inside-a-class/ Share on other sites More sharing options...
trq Posted December 2, 2010 Share Posted December 2, 2010 Sounds pretty inflexible to me. You really should take a look at some MVC implementations. Quote Link to comment https://forums.phpfreaks.com/topic/220509-oop-echo-inside-a-class/#findComment-1142424 Share on other sites More sharing options...
btherl Posted December 3, 2010 Share Posted December 3, 2010 I think it's fine to echo inside the class if the purpose of the class is to echo your page. The Smarty display method is an example of this. But within the class I would recommend that you generate the entire output in a string, and only echo it with a single statement at the end. IE your display method would be function display() { $output = $this->generate(); echo $output; } And no other method from this class (and all other classes) would echo anything. Quote Link to comment https://forums.phpfreaks.com/topic/220509-oop-echo-inside-a-class/#findComment-1142429 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.