단순 리턴함수.



stdafx.h
#pragma once

#include "zend_config.w32.h"
#include "php.h"
#include "php_myext.h"



php_myext.h
#ifndef PHP_MYEXT_H
#define PHP_MYEXT_H 1

#define PHP_MYEXT_VERSION "1.0"
#define PHP_MYEXT_EXTNAME "myext"

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

extern "C" {
    #ifdef ZTS
    #include "TSRM.h"
    #endif
}

PHP_FUNCTION(func_string);
PHP_FUNCTION(func_long);
PHP_FUNCTION(func_double);
PHP_FUNCTION(func_bool);
PHP_FUNCTION(func_null);

extern zend_module_entry myext_module_entry;
#define phpext_myext_ptr &myext_module_enrty;

#endif



myext.cpp
#include "stdafx.h"

static function_entry myext_functions[] = {
    PHP_FE(func_string, NULL)
    PHP_FE(func_long ,NULL)
    PHP_FE(func_double ,NULL)
    PHP_FE(func_bool ,NULL)
    PHP_FE(func_null ,NULL)
    {NULL, NULL, NULL}
};

zend_module_entry myext_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
    STANDARD_MODULE_HEADER,
#endif
    PHP_MYEXT_EXTNAME,
    myext_functions,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
#if ZEND_MODULE_API_NO >= 20010901
    PHP_MYEXT_VERSION,
#endif
    STANDARD_MODULE_PROPERTIES
};

extern "C" {
    ZEND_GET_MODULE(myext)
}

PHP_FUNCTION(func_string)
{
    RETURN_STRING("String", 1);
}

PHP_FUNCTION(func_long)
{
    RETURN_LONG(123);
}

PHP_FUNCTION(func_double)
{
    RETURN_DOUBLE(3.141592);
}

PHP_FUNCTION(func_bool)
{
    RETURN_TRUE; // = RETURN_BOOL(1);
    //RETURN_FALSE; // = RETURN_BOOL(0);
}

PHP_FUNCTION(func_null)
{
    RETURN_NULL();
}





위의 소스대로 프로젝트를 구성하고 빌드한 다음 모듈을 로드시키고 아래의 PHP 소스를 실행시킨 결과가 다음과 같다면 성공.


<?php
var_dump(func_string());
var_dump(func_long());
var_dump(func_double());
var_dump(func_bool());
var_dump(func_null());



결과
---------- PHP ----------
string(6) "String"
int(123)
float(3.141592)
bool(false)
NULL
Posted by bloodguy
,