1

我写了一个非常简单的 PHP 扩展。现在我希望它在启动时读取文件。这是我的代码:

#define PHP_COMPILER_ID  "VC6"


#include <fstream>  
#include "php.h"


int number = 0;
ZEND_FUNCTION(use_html);

//declaration
ZEND_MINIT_FUNCTION(use_html);
zend_function_entry use_functions[] = 
{
    ZEND_FE(use_html, NULL)
    {NULL, NULL, NULL}
};

zend_module_entry use_html_module_entry = 
{
    STANDARD_MODULE_HEADER,
    "First_Extension",
    use_functions,
    ZEND_MINIT(use_html), 
    NULL, NULL, NULL, NULL,
    "1.0.0-tutorial",
    STANDARD_MODULE_PROPERTIES
};

ZEND_GET_MODULE(use_html);

ZEND_FUNCTION(use_html)
{
     bool useHtml;

     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &useHtml) == FAILURE)
     {
         E_ERROR;
         return;
     }

     if(useHtml)
     {
         php_printf("This string uses <a href='#'>Html</a>");
     }
     else
     {
         int sum = 0;
         int i = 0;
         for(i;i<100000;i++)
             sum += i;

         RETURN_LONG(number);
     }

     return;
}

ZEND_MINIT_FUNCTION(use_html)
{
    std::ifstream infile("file.txt");
    number++;
    return SUCCESS;
}

错误消息是: Error 5 error C2491: 'std::endl' : definition of dllimport function not allowed c:\program files\microsoft visual studio 10.0\vc\include\ostream 1004 1 php_extension1

我也尝试更改包含的顺序,但没有帮助。

编辑

这是来自 ostream 的有问题的部分

_CRTIMP2_PURE inline basic_ostream<char, char_traits<char> >&
    __CLRCALL_OR_CDECL endl(basic_ostream<char, char_traits<char> >& _Ostr)
    {   // insert newline and flush byte stream
    _Ostr.put('\n');
    _Ostr.flush();
    return (_Ostr);
    }
4

1 回答 1

1

我找到了一个解决方案:对于 php 扩展开发,我只#include <string>在 zend_config.w32.h 中添加了它,它编译得很好。欲了解更多信息:http ://social.msdn.microsoft.com/Forums/hu-HU/vcgeneral/thread/94ed21c2-7128-4149-8a8f-05fc195a812c

于 2012-10-21T18:12:00.750 回答