Hi, I have to port a C++ program to PHP in order to use it on a Web server and I don't understand how to go about it. I have absolutely zero experience with PHP. I'm going to go about this very incrementally. So, my first step is to convert the classes into PHP.
How do I implement
class semUnit
{
public:
D2bar* getAgent();
D2bar* getTheme();
semUnit();
semUnit(D2bar* a, D2bar* b);
string printAgent();
string printTheme();
private:
D2bar* Agent;
D2bar* Theme;
};
in PHP?
I've heard that PHP5 offers the ability to distinguish between private and public so I'd like to use this feature.
Help creating PHP classes using public/private from C++
Moderator: General Moderators
-
noisymouse
- Forum Newbie
- Posts: 3
- Joined: Mon Dec 14, 2009 3:50 pm
-
noisymouse
- Forum Newbie
- Posts: 3
- Joined: Mon Dec 14, 2009 3:50 pm
Re: Help creating PHP classes using public/private from C++
Ok, here is my attempt to implement that in PHP:
Code: Select all
class semUnit
{
private $Agent = NULL;
private $Theme = NULL;
public function __construct($a,$b) {
$this->Agent = a;
$this->Theme = b;
}
public function getAgent() {
return $this->Agent;
}
public function getTheme() {
return $this->Theme;
}
public function printAgent() {
return $Agent->print(); //not print is a member function of the class that $Agent is. DOES THIS WORK?
}
public function printTheme() {
return $Theme->print();
}
}
}Re: Help creating PHP classes using public/private from C++
Actually no. You cannoisymouse wrote:Hi, I have to port a C++ program to PHP in order to use it on a Web server
a) Modify it to run as a CGI program - could take a fair bit of work, depending - or
b) Execute it from PHP using a function like exec