I have the following C++ function:
void foo() {
std::cout << "bar" << std::endl;
}
I’m porting this to PHP via SWIG. Everything compiles fine and the extension loads properly. I’m able to call foo() from PHP, but I only see the bar output if I run the PHP script from the command line.
$ php script.php
bar
If I load the script in the browser, nothing appears. Why does it not show bar in this case?
You can’t print to stdout directly. This will of course only work if you’re using the CLI SAPI. Use
php_printfor any of these: