Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting C to PHP? [closed]

Is there any tool available that takes C code as input and outputs valid PHP files?

I'd like to use the SAC API but all the implementations currently available are in C, Java, Ruby and Perl. I wonder if the C implementation can be converted to PHP easily.

like image 968
eozzy Avatar asked Feb 27 '23 14:02

eozzy


1 Answers

I've never seen any tool to do that ; but the way that's generally used when one wants to use some C library from PHP is to write a PHP extension, that acts as some kind of "bridge" between the PHP userland-code, and the C library.

That's how you are able to use the curl library from PHP, for example.


A couple of interesting reads on that matter :

  • Extension Writing Part I: Introduction to PHP and Zend
  • Extension Writing Part II: Parameters, Arrays, and ZVALs
  • Extension Writing Part II: Parameters, Arrays, and ZVALs [continued]
  • Extension Writing Part III: Resources
  • Wrapping C++ Classes in a PHP Extension

And, if you are really interested by the subject, and ready to spend some money on it, you could also buy the book Extending and Embedding PHP (some pages are available as preview on Google Books too) ; I've seen a couple of times that it was the book to read when interested on this subject (In fact, I've bought it some time ago, and it's an interesting read, even if you don't plan on writing an extension right now)

BTW, the author of that book is also the author of the first four articles I linked to ;-)

like image 147
Pascal MARTIN Avatar answered Mar 08 '23 00:03

Pascal MARTIN