代码改变世界

php扩展加载原理demo

2021-12-30 20:53  虎背熊腰  阅读(50)  评论(0)    收藏  举报

php 的扩展原理就是函数的动态注入和调用,简单demo如下

 

head.h
=============
typedef struct function{
char * name;
void (* handler)();
} FUNCTION;

FUNCTION * function_list[10];

 

 

helloword.c
===========
#include <stdio.h>
#include "header.h"
int helloword(){
printf("%s","helloword");
}

FUNCTION f=
{
"helloword",
helloword
};

void get_module()
{
function_list[0] = &f;
}

 

maic.c
===============
#include <stdio.h>
#include "head.h"
extern void get_module();
int main(){
get_module();
function_list[0]->handler();
}