惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
雷峰网
雷峰网
博客园 - 叶小钗
V
V2EX
博客园 - Franky
博客园_首页
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
S
SegmentFault 最新的问题
B
Blog RSS Feed
博客园 - 【当耐特】
D
Docker
N
Netflix TechBlog - Medium

zodream梦想开源/个人编程日记

文件解析笔记-zodream梦想开源/个人编程日记 密码本开发笔记之读写与保存-zodream梦想开源/个人编程日记 SkiaSharp 把 pixel byte[] 转成 SKBitmap-zodream梦想开源/个人编程日记 nas 使用 Docker 安装 gogs-zodream梦想开源/个人编程日记 复制 android 手机中的文件到电脑-zodream梦想开源/个人编程日记 周报:寻找优质的周刊-zodream梦想开源/个人编程日记 开发日志:对Markdown的代码块新增引用来源支持-zodream梦想开源/个人编程日记 周报:怎么写技术类的教程文章-zodream梦想开源/个人编程日记 css display:flex 布局尺寸超出问题-zodream梦想开源/个人编程日记 周报:SEO优化的思考-zodream梦想开源/个人编程日记 Edge 浏览器不适用 Edge Image Viewer 打开图片 -zodream梦想开源/个人编程日记 SEO 学习笔记(一) 内容来源-zodream梦想开源/个人编程日记 PHP 实现双因素身份认证(2FA)-zodream梦想开源/个人编程日记 WPF MVVM 获取List 多选数据-zodream梦想开源/个人编程日记 Burp Suite 抓包-zodream梦想开源/个人编程日记 使用 indexnow 注意事项-zodream梦想开源/个人编程日记 Godot 使用字体图标 例如: Iconfont、FontAwesome-zodream梦想开源/个人编程日记 angular 15 对指定页面进行访问限制-zodream梦想开源/个人编程日记 CSS 使用 column-count 实现瀑布流出现内容分割的解决办法-zodream梦想开源/个人编程日记 input 确认按键事件在手机端不生效-zodream梦想开源/个人编程日记 C# 使用socket 进行通讯-zodream梦想开源/个人编程日记 Maui开发中Windows应用开启管理员权限-zodream梦想开源/个人编程日记 Maui 中自定义控件-zodream梦想开源/个人编程日记 angular 14 使用 ng-template 实现tree 结构显示-zodream梦想开源/个人编程日记 c# 动态安装和卸载dll-zodream梦想开源/个人编程日记 慎用 CompositionTarget.Rendering-zodream梦想开源/个人编程日记 c# 重写 c++ 程序笔记:数据初始化-zodream梦想开源/个人编程日记 源码编译 aseprite-zodream梦想开源/个人编程日记 记录一下字符串分隔split各语言之间的不同-zodream梦想开源/个人编程日记 c# Gzip解码无头内容-zodream梦想开源/个人编程日记
VS2019 开发PHP 拓展(四)创建 function-zodream梦想开源/个...
zodream · 2020-03-23 · via zodream梦想开源/个人编程日记

VS2019 开发PHP 拓展(四)创建 function

无参无返回

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_test1, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

/* {{{ void test1()
 */
PHP_FUNCTION(test1)
{
    ZEND_PARSE_PARAMETERS_NONE();

    php_printf("The extension %s is loaded and working!\r\n", "zodream");
}
/* }}} */
static const zend_function_entry zodream_functions[] = {
    PHP_FE(test1,       arginfo_test1)
    PHP_FE_END
};

12345678910111213141516

1参无返回

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_test2, 0, 0, IS_VOID, 0)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_END_ARG_INFO()

/* {{{ void test2()
 */
PHP_FUNCTION(test2)
{
    char *var = "World";
    size_t var_len = sizeof("World") - 1;

    ZEND_PARSE_PARAMETERS_START(0, 1)
        Z_PARAM_OPTIONAL
        Z_PARAM_STRING(var, var_len)
    ZEND_PARSE_PARAMETERS_END();

    php_printf("Hello %s\r\n", var);
}
/* }}} */
static const zend_function_entry zodream_functions[] = {
    PHP_FE(test2,       arginfo_test2)
    PHP_FE_END
};

1234567891011121314151617181920212223

多参无返回

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_test3, 0, 0, IS_VOID, 2)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, config, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

/* {{{ void test3(string $str, array $config)
 */
PHP_FUNCTION(test3)
{
    zval* config, *entry;
    zend_ulong num_idx;
    zend_string* str_idx;
    char* var = "World";
    size_t var_len = sizeof("World") - 1;

    ZEND_PARSE_PARAMETERS_START(2, 2)
        Z_PARAM_STRING(var, var_len)
        Z_PARAM_ARRAY(config)
    ZEND_PARSE_PARAMETERS_END();

    php_printf("Hello %s\r\n", var);
    // 循环打印为字符串的值
    ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(config), num_idx, str_idx, entry) {
        ZVAL_DEREF(entry);
        if (Z_TYPE_P(entry) == IS_STRING) {
            php_printf("Hello %s\r\n", Z_STRVAL_P(entry));
        }
    } ZEND_HASH_FOREACH_END();
}
/* }}} */
static const zend_function_entry zodream_functions[] = {
    PHP_FE(test3,       arginfo_test3)
    PHP_FE_END
};

12345678910111213141516171819202122232425262728293031323334

无参有返回

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_test4, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()

/* {{{ void test4()
 */
PHP_FUNCTION(test4)
{
    ZEND_PARSE_PARAMETERS_NONE();

    zend_string* retval = strpprintf(0, "test 4");
    RETURN_STR(retval);
}
/* }}} */
static const zend_function_entry zodream_functions[] = {
    PHP_FE(test4,       arginfo_test4)
    PHP_FE_END
};

1234567891011121314151617

有参有返回

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_test5, 0, 0, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_END_ARG_INFO()

/* {{{ void test5()
 */
PHP_FUNCTION(test5)
{
    char* var = "World";
    size_t var_len = sizeof("World") - 1;
    zend_string* retval;

    ZEND_PARSE_PARAMETERS_START(0, 1)
        Z_PARAM_OPTIONAL
        Z_PARAM_STRING(var, var_len)
    ZEND_PARSE_PARAMETERS_END();

    retval = strpprintf(0, "Hello %s", var);

    RETURN_STR(retval);
}
/* }}} */
static const zend_function_entry zodream_functions[] = {
    PHP_FE(test5,       arginfo_test5)
    PHP_FE_END
};

1234567891011121314151617181920212223242526

转载请保留原文链接: https://zodream.cn/blog/id/105.html