简体   繁体   English

ob_start(); 回调函数

[英]ob_start(); callback function

Is there any difference (performance or otherwise) to use ob_start in the following ways? 在以下方面使用ob_start是否有任何差异(性能或其他方面)?

Option 1: 选项1:

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

Option 2: 选项2:

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

Thanks! 谢谢!

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 . 唯一的区别是,在第一种情况下,您将声明一个全局函数ob_handle ,您可以从其他地方再次使用它并占用全局名称ob_handle In the second case, you cannot refer to the anonymous function from elsewhere again. 在第二种情况下,您不能再从其他地方引用匿名函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM