1

I would like a straight forward answer if require_once is same when you do output buffering.

Approach 1

1     require_once __DIR__ . '/src/MyBaseClass.php';

Approach 2

1     ob_start();
2     require_once __DIR__ . '/src/MyBaseClass.php';
3     echo ob_get_clean();

Will these produce exactly similar behavior of loading the class?

Oh! One more thing! Just a clarification...

On Approach 2, is MyBaseClass class on Line 2 already loaded (and ready for use)? Or is it still necessary to output the buffer (as shown in Line 3) in order to load the class in runtime?

Thanks in advance. Cheers!

Allen Linatoc
  • 624
  • 7
  • 17

1 Answers1

0

"Both will load the class to be used on the next line of codes.... output buffering is used in order to capture unecessary output if the FILE, not the CLASS, that contains unecessary PRINT messages(debug messages, whitespaces) which affects the next lines of code.. It depends on you if you want to keep the buffered output or throw it out..."

-- An answer from Jeffrey Santiago

Allen Linatoc
  • 624
  • 7
  • 17