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
https://forums.phpfreaks.com/topic/176465-php-vs-c/
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
https://forums.phpfreaks.com/topic/176465-php-vs-c/#findComment-930611
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
https://forums.phpfreaks.com/topic/176465-php-vs-c/#findComment-931135
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.