Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问如何在PHPX_FUNCTION写的函数里返回值呢? #30

Closed
52fhy opened this issue Aug 28, 2017 · 6 comments
Closed

请问如何在PHPX_FUNCTION写的函数里返回值呢? #30

52fhy opened this issue Aug 28, 2017 · 6 comments

Comments

@52fhy
Copy link

52fhy commented Aug 28, 2017

No description provided.

@solorush
Copy link

通过形参retval返回
#define PHPX_FUNCTION(c) void c(Args &args, Variant &retval)

@52fhy
Copy link
Author

52fhy commented Aug 29, 2017

补充说明:

使用retval赋值可以给函数返回返回值。但是发现bug:
1、在CentOS Linux release 7.3.1611(gcc 4.8.5)上给retval赋值后是函数可以正常返回返回值的;
2、在deepin15.4.1(Linux version 4.9.0-deepin9-amd64 (yangbo@deepin.com) (gcc version 6.3.0 20170321 (Debian 6.3.0-11) ))上返回值始终是NULL。

下面是代码:
extension.cpp

#include "phpx.h"

#include <iostream>

using namespace php;
using namespace std;

PHPX_FUNCTION(func_test)
{
    retval = 1234;
}

PHPX_EXTENSION()
{
    Extension *extension = new Extension("my_ext", "0.0.1");

    extension->onStart = [extension]() noexcept
    {
    };


    extension->registerFunction(PHPX_FN(func_test));

    extension->info(
    {
        "my_ext support", "enabled"
    },
    {
        { "author", "Yjc" },
        { "version", extension->version },
        { "date", "2017-08-29" },
    });

    return extension;
}

echo.php

<?php
var_dump(func_test());

输出:

$ php echo.php 
NULL

@52fhy
Copy link
Author

52fhy commented Aug 29, 2017

@matyhtf 麻烦您看看这个兼容性问题。

@matyhtf
Copy link
Member

matyhtf commented Aug 29, 2017

检查的代码是不是最新的,最近的一次提交,刚刚修复了 retval 的问题

@52fhy
Copy link
Author

52fhy commented Aug 29, 2017

问题已解决。作者已经更新了一版,需要升级到最新版本,删除旧的so文件后重新编译PHP-X和扩展。感谢作者的回复!祝PHP-X越来越好!

@52fhy
Copy link
Author

52fhy commented Aug 29, 2017

close

@52fhy 52fhy closed this as completed Aug 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants