开发者

Call c++ function into a PHP code

I have some c++ OOP classes (separated files开发者_JS百科) , and I want to create objects in PHP code that can call the functions in those classes.. (PHP classes derived from c++ classes).

Because the php is not more than a scripting language, I've got some functions that can only writen by a low level language that has a closed relation with the hardware, (so the c++ is the best choice).

but I want to use those functions(that are without a main function) in a php code, is this possible?.


PHP classes derived from c++ classes

I don't think there is any way for such close interaction.

You would have to either

  • Write a PHP extension in C. Related article: Extension Writing Part I: Introduction to PHP and Zend

  • Write an external program and run it using exec()


I think the easiest to achieve what you intend to do is to write your C++ functions and export them flat (i.e. not as class). And, using SWIG, write a facade class that calls those functions. In PHP, you'd simply use your facade class in the OOP manner.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜