0

I have some c++ OOP classes (separated files) , 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?.

2

2 Answers 2

2

PHP classes derived from c++ classes

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

You would have to either

Sign up to request clarification or add additional context in comments.

3 Comments

"Write an external program and run it using exec()", But I don't want to write it as a programm, because it has no main function. I only want to call the source code functions, that's all.
@Simo in that case, you'll have to write a PHP extension. I don't think there is any other way.
As a note: you can always write an extension in C++, and then the parts that interact with PHP can be written in C. Assuming you get all the compiler and linker magic correct, it should be doable (ie: extern C in the C++ code, compile your code with the same GCC version as what compiled the php code... etc. etc.)
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.