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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
noisymouse
Forum Newbie
Posts: 3
Joined: Mon Dec 14, 2009 3:50 pm

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

Post 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.
noisymouse
Forum Newbie
Posts: 3
Joined: Mon Dec 14, 2009 3:50 pm

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

Post 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();
    }
}
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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
Post Reply