I have come across a C library from which I want to use functions inside PHP. This question has put me on track of php-cpp. But it is not very clear to me anywhere if I can use php-cpp for pure C.
Most sources on the internet say it's trivial to mix C with C++, so I want to know if it's worth investing my time learning what I need to learn to achieve the goal.
But it is not very clear to me anywhere if I can use php-cpp for pure C.
If you try to include any C++ code that actually has C++ features that C does not support in a C program. It simply won't compile.
Most sources on the internet say it's trivial to mix C with C++
That is only the case when you including C code to a C++ program. Even then, there are a few exceptions.
If you are doing this because you do not know C++, you can write a C++ program as if it were C (with a few exceptions, like void pointers) if you are careful enough.
PHP-CPP is a C++ library that can be used to develop PHP extensions. It is not required to develop PHP extensions, although it may make your life a little easier. If you don't know C++, or if you don't want to use it, you can safely ignore PHP-CPP. Refer to "Getting Started with PHP Extension Development" for some resources on developing PHP extensions (in C).
It is perfectly possible to call C libraries from C++. In most cases, the exact same syntax can be used; at most, you may need to wrap C header files with extern "C" { ... }.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With