Kovo
Kovo

Reputation: 1717

ob_start(); callback function

Is there any difference (performance or otherwise) to use ob_start in the following ways?

Option 1:

function ob_handle($buffer){/*do something, and return buffer*/}
ob_start('ob_handle');

Option 2:

ob_start(function($buffer){/*do something, and return buffer*/});

Thanks!

Upvotes: 1

Views: 915

Answers (1)

deceze
deceze

Reputation: 522081

There's hardly a difference performance-wise. It's just a matter of how the callback function is declared, it doesn't change anything about how the function is used or executed. If you want to know for sure, benchmark it.

The only difference is that in the first case you're declaring a global function ob_handle, which you can use again from elsewhere and which takes up the global name ob_handle. In the second case, you cannot refer to the anonymous function from elsewhere again.

Upvotes: 3

Related Questions