Page 1 of 1

Help creating PHP classes using public/private from C++

Posted: Mon Dec 14, 2009 4:09 pm
by noisymouse
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.

Re: Help creating PHP classes using public/private from C++

Posted: Mon Dec 14, 2009 4:30 pm
by noisymouse
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++

Posted: Mon Dec 14, 2009 5:30 pm
by requinix
noisymouse wrote:Hi, I have to port a C++ program to PHP in order to use it on a Web server
Actually no. You can
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