Jump to content

PHP vs C++


Recommended Posts

Excuse my ignorance but I'd like to know the differences between scripting in php and C++. I do realize the obvious differences in php being interpreted and C++ being compiled. I'd just like to know how hard it would be for me to start learning C++ only having scripted in PHP. I've read that PHP is based on C/C++.

Link to comment
Share on other sites

I've read that PHP is based on C/C++.

PHP is also written in C

 

But anyway C/C++ are lower level programming languages. It's closer at hardware level. OOP in C++ can be a bit confusing (at least it was to me) at first since you don't encapsulate the methods in the class like PHP and Java.

 

If you're only familiar with PHP, working with pointers will be completely new to you. This is were you can screw up big time because you can create memory leaks if you don't use pointers correctly.

 

 

Link to comment
Share on other sites

"OOP in C++ can be a bit confusing (at least it was to me) at first since you don't encapsulate the methods in the class like PHP and Java. "

 

 

Errr.... What do you mean?

Hmm that was vague I guess. Just took a code sniplet of wikipedia to clarify.

class person
{
  std::string name;
  int age;
public:
  person() : age(5) { }
  void print() const;
};

void person::print() const
{
  cout << name << ";" << this->age << endl;
  /* we don't have to mention what "name" and "age" are,
     because it automatically refers back to the member variables.
     The "this" keyword is an expression whose value is the address
     of the object for which the member was invoked. Its type is 
     const person*, because the function is declared const.
*/
}

 

The "print" method  is after the last curly bracket while the print method is declared public between the curly brackets. That was pretty much the first time I'd seen this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.