@@ -3,6 +3,7 @@ package phpgo
33/*
44#include "extension.h"
55#include "../zend/compat.h"
6+ #include "../zend/szend.h"
67
78#include <php.h>
89#include <zend_exceptions.h>
@@ -19,9 +20,10 @@ import "errors"
1920import "fmt"
2021import "log"
2122import "os"
22- import "github.com/kitech/php-go/zend"
2323import "strings"
2424
25+ import "github.com/kitech/php-go/zend"
26+
2527// 一个程序只能创建一个扩展
2628// 所以使用全局变量也没有问题。
2729var (
@@ -336,11 +338,22 @@ func AddConstant(name string, val interface{}, namespace interface{}) {
336338// 内置函数注册,内置类注册。
337339func addBuiltins () {
338340 // nice fix exit crash bug.
339- AddFunc ("GoExit" , func (code int ) { os .Exit (code ) })
340- AddFunc ("GoGo" , func (fn interface {}) { log .Println (fn ) })
341- AddFunc ("GoPanic" , func () { panic ("got" ) })
342- AddFunc ("GoRecover" , func () { recover () })
343- AddFunc ("GoPrintln" , func (p0 int , v interface {}) { log .Println (v , 123333 ) })
341+ var iret C.int = 0
342+ if iret = C .gozend_function_registered (C .CString ("GoExit" )); iret == C .int (0 ) {
343+ AddFunc ("GoExit" , func (code int ) { os .Exit (code ) })
344+ }
345+ if iret = C .gozend_function_registered (C .CString ("GoGo" )); iret == C .int (0 ) {
346+ AddFunc ("GoGo" , func (fn interface {}) { log .Println (fn ) })
347+ }
348+ if iret = C .gozend_function_registered (C .CString ("GoPanic" )); iret == C .int (0 ) {
349+ AddFunc ("GoPanic" , func () { panic ("got" ) })
350+ }
351+ if iret = C .gozend_function_registered (C .CString ("GoRecover" )); iret == C .int (0 ) {
352+ AddFunc ("GoRecover" , func () { recover () })
353+ }
354+ if iret = C .gozend_function_registered (C .CString ("GoPrintln" )); iret == C .int (0 ) {
355+ AddFunc ("GoPrintln" , func (p0 int , v interface {}) { log .Println (v , 123333 ) })
356+ }
344357}
345358
346359// 注册php module 初始化函数
0 commit comments