Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8296959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:13:23+00:00 2026-06-08T15:13:23+00:00

is there anything wrong with using html inside a class function? I call it

  • 0

is there anything wrong with using html inside a class function? I call it in the DOM so I don’t need a string returned.

public function the_contact_table(){
    ?>
    <div>
        some html here
    </div>
    <?php
}

Also when I do need the string I use this method? Is there a better way or is this relatively standard?

public function get_single(){
    ob_start();?>
        <div class='staff-member single'>
            <div class='col left'>
                <div class='thumbnail'>
                    thumbnail
                </div>
                <?php $this->the_contact_table(); ?>
            </div>
            <div class='col right'>

            </div>
        </div>      
    <?php
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}

UPDATE

I should have explained why i am doing this. I’m making a WordPress plugin and want to control a post types output. So I am using a filter like below

public function filter_single($content){
     global $post;
     if ($post->post_type == 'staff-member') {

         $sm = new JM_Staff_Member($post);
         $content = $sm->get_single();
     }
     return $content;
}

So as you can see, I must return a string to the wordpress core

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:13:28+00:00Added an answer on June 8, 2026 at 3:13 pm

    You should be using HEREDOC instead of output buffering if you want to store a long string into a variable. It looks like this:

    $content = <<<EOD
    content here
    EOD;
    

    EOD can be anything, but note two important things:

    1. It can’t have any whitespace in front of it and it must be on it’s own line
    2. It shouldn’t be a string that could be found within your content

    If you are using PHP >= 5.3, then you should use NOWDOC, which does not parse for variable inside the doc (unless you need this). The only different with the syntax of NOWDOC is that the sentinel is enclosed in quotes:

    $content = <<<'EOD'
    content here
    EOD;
    

    The reason why I’d stray away from output buffering is that it prevents the server from chunking the data sent to the client. This means that requests will seem slower because instead of the content being progressively sent to the client and displayed, it is forced to be sent all at once. Output buffering is a hack for situations when functions carelessly echo data instead of returning it or a tool for certain applications with the specific need for it. I’d also imagine that you’d take a hit on execution time if you used output buffering (because it involves function calls) versus HEREDOCing the string into a variable or including a view.

    Now to answer the question about whether it is appropriate, I would say that in an MVC application all HTML and other content should be contained within its own view. Then a controller can call a view to display itself and doesn’t have to worry about knowing the code involved in displaying the view. You can still pass information (like titles, authors, arrays of tags, etc.) to views, but the goal here is separating the content from the logic.

    That said, WordPress templates and code looks pretty sloppy to begin with and loosely if not at all implements MVC so if it’s too much work to create a view for this, I’d say the sloppiness would fit in with WP’s style.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anything wrong with having a single class (one .h) implemented over multiple
Is there anything wrong with this code? My entity is not getting updated. public
Is there anything wrong or inherently unsafe about the way I've programmed this? I'm
Is there anything wrong with this code or can this be done more efficiently?
Is there anything wrong with checking so many things in this unit test?: ActualModel
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
i just wondering is there any performance issue or anything thing wrong if that
is there anything special I need to do to get ASP.NET MVC3 enabled on
Flex: public function callFromJavaScript():String { test.label='dfdsfsdf'; return "1"; } public function init():void { ExternalInterface.addCallback("sendToFlash",
is there anything more comfortable than this to detect a special page? The page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.