简体   繁体   English

C ++ PHP扩展

[英]C++ PHP extension

I wrote a very simple PHP extension. 我写了一个非常简单的PHP扩展。 Now I want it to read in a file on startup. 现在,我希望它在启动时读入文件。 Here is my code: 这是我的代码:

#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;
}

and the error message is: 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 错误消息是:错误5错误C2491:'std :: endl':不允许dllimport函数的定义c:\\ program files \\ microsoft visual studio 10.0 \\ vc \\ include \\ ostream 1004 1 php_extension1

I also tried to change the order of include, but it didnt help. 我也尝试更改包含的顺序,但没有帮助。

EDIT 编辑

here is the problematical part from ostream 这是来自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);
    }

I have found a solution: for php extension developement I only added #include <string> in zend_config.w32.h and it compiled fine. 我找到了一个解决方案:对于php扩展开发,我仅在zend_config.w32.h中添加#include <string> ,并且编译良好。 for more info: http://social.msdn.microsoft.com/Forums/hu-HU/vcgeneral/thread/94ed21c2-7128-4149-8a8f-05fc195a812c 有关更多信息: http : //social.msdn.microsoft.com/Forums/hu-HU/vcgeneral/thread/94ed21c2-7128-4149-8a8f-05fc195a812c

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

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