In a PHP extension, recommended way to return the value from and std::string
问题 We have a simple PHP function, whose purpose is to call a C++ free function std::string callLibrary(std::string) and to return its std::string return value. It currently looks like that: PHP_FUNCTION(call_library) { char *arg = NULL; size_t arg_len, len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) { return; } // Call underlying library std::string callResult = callLibrary(arg); zend_string * result = zend_string_init(callResult.c_str(), callResult.size(), 0);