输出和错误
最后更新于:2022-04-02 02:33:09
[TOC]
## 示例
### 输出
```
#include
#include
void myFunction()
{
// endl 自带换行
Php::out << "example output1" << std::endl;
Php::out << "example output2\n" << std::flush;
Php::out << "example ";
Php::out << "output3\n";
Php::out.flush();
// 自己测试失效
Php::echo("Example output\n");
}
extern "C" {
PHPCPP_EXPORT void *get_module() {
static Php::Extension extension("my_extension", "1.0");
extension.add("myFunction");
return extension;
}
}
```
```
#include
void myFunction()
{
Php::notice << "this is a notice \n" << std::flush;
Php::warning << "this is a warning\n" << std::flush;
// 通知用户调用了一个已弃用的函数
Php::deprecated << "this method is deprecated\n" << std::flush;
// 抛出错误
Php::error << "fatal error\n" << std::flush;
}
...
```
```
set_error_handler("error_handler");
function error_handler($errno, $errstring, $errfile, $line, $trace) {
echo $errstring;
return ;
}
myFunction();
```
';