I have PHP background and want to start learning C++. How should I proceed?
-
5I wouldn't say they're very similar beyond syntax. You should start near the start. – cthom06 Sep 22 '10 at 17:32
-
1PHP and C++ do not have very much in common. There are some basic things that are quite different, actually. Some examples are pointers and types. – jwueller Sep 22 '10 at 17:37
-
25Lol, "PhP expert" did not impress the C++ community. – Hamish Grubijan Sep 22 '10 at 17:38
-
1You are in for a big surprise if you think they are "very similar." PHP was designed to be very easy to use. C++, not so much. – NullUserException Sep 22 '10 at 17:51
-
If you are good with PHP it wont take long to get competent with C++, It never takes as long when learning a second(or thrid/forth) language. Knowing the syntax from PHP will help. – Sep 22 '10 at 17:57
-
5@PhilCK: Knowing the syntax won't help much at all. The slow part about learning a new language is the new ideas and practices, not the syntax. If the concepts are too dissimilar, knowing one programming language (like C) can apparently slow down learning the second (perhaps Scheme). Once one knows several different languages, learning another typically involves learning fewer new things, and so goes faster. – David Thornley Sep 22 '10 at 18:09
-
8If you claim to be an expert, you're not. – Malfist Sep 22 '10 at 18:17
-
@Malfist: want to see some of my works? – tazphoenix Sep 22 '10 at 18:36
-
1@David Thornley: Well I watched 1st year students struggling with syntax, and it was always semicolons and curly braces that trip them up time and time again. A lot of time was wasted debugging simple errors like those. – Sep 24 '10 at 08:47
-
If the only languages you know are scripting languages such as PHP and JavaScript then the concept of compiling will take time to learn. Also "includes" in PHP are very different from "#includes" in C/C++. Strings are different and arrays are **very** different. C/C++ are very particular about type (are type-safe). There are differences in syntax of course but conceptually the preceding are the important differences I have found. – Sam Hobbs Jan 03 '17 at 19:52
-
@Malfist be wary; tazphoenix is about to show you **his works**! #terrified – Aug 25 '17 at 20:30
6 Answers
Start at the start. The similarities between PHP and C++ will take about half an hour to get through ("this is an object, this is a loop, ..."), and there are subtle differences which will kill you if you're not paying attention during that half hour. Learning C++ will take months to years, depending what you mean by "learn". It's just not a worthwhile optimisation.

- 273,490
- 39
- 460
- 699
Unfortunately, with this particular subject you'll see a lot of superiority and thus not get a very straight answer. This is due to the nature of PHP's structure, how common it is to see it in "casual" form (Think WordPress), and it's ease of use and relatively small "learning curve".
To be clear, PHP and C++ are very similar on the surface - But the same could be said for any C-based language. You have your variables, loops, arrays, classes, etc. But where do they differ?
Beyond syntax (Which is quite similar anyway), PHP was designed to be easy to use, while C++ was designed to be efficient (And as technology evolves, that becomes less and less relevant). That aside, PHP was designed to work in a web-server environment while C++ is for applications in general (You can even develop web apps in C++, if you want to).
Down to technical details, as mentioned before, C++ was designed to be efficient and thus allows close access to memory management & co. Like any high-level languages, it was designed to shield the user from the raw technical aspects of the machine (Rather than writing in assembly, or, heaven forbid, machine code). PHP goes one step further and leaves the programmer to only focus on the logic of the application.
To conclude, C++ is like PHP on the surface, but a whole lot different in design AND purpose. C++ performs operations beyond the scope of PHP's abilities, and thus is a more complicated language and takes longer to learn. Personally, I had an easier time 'learning C++' after having dealt with PHP because it managed to separately introduce numerous concepts in a very straightforward way.
PHP:
<?php
$count = 0;
while ($count <= 10)
{
echo $count,"\n";
$count++;
}
C++:
#include <iostream>
int main()
{
int count = 0;
while (count <= 10)
{
std::cout << count << "\n";
count++;
}
}
In the end, as with most languages, the only obstacle is learning the differences. Really, it's just logic/logical thinking that you express in a readable format.

- 1,547
- 1
- 18
- 23
Because you know PHP, you'll "feel at home" a little bit when you start to learn C++ because you'll be used to typing semicolons at the end of statements, using braces for conditionals, etc.
You'll likely be able to progress more quickly because you know PHP, but there are C++-only constructs and ideas that will be new. That, and though the syntaxes are similar, they're not identical.

- 15,990
- 10
- 70
- 110
As others have said, the similarities are superficial at best. Basic C syntax is pretty much the same - loops, conditionals, etc, but the interesting parts of the language are vastly different.
This is going to be a big learning curve, but when you reach the other side you'll be a much more aware and qualified developer.
One of the big problems that I foresee is basic coding style. The majority of the PHP code that I've seen is poorly structured at best, relying on a mashup of procedural code, objects and misc. hacks. Memory management is nearly a non-issue in PHP, whereas you need to always be aware of it in C++.
Also, note that even the differences between C and C++ (there's no such thing as C/C++, despite what the book publishers seem to think) are substantial.

- 28,657
- 18
- 88
- 151
-
C is nearly a subset of C++. I use "C/C++" to refer to the features common to both since just "C" implies features unique to it. – Sam Hobbs Jan 03 '17 at 19:42
I would start from the beginning. I started on Java which is more similar than PHP and I still made a point to read the book I had from the beginning. It's important to know the little subtleties about the language. As for resources, I have no strong opinion on any book I've seen, but I do prefer books. This is the book I started with. It got the job done, but I know my boss/professor wasn't happy with it and has since replaced it.

- 1,978
- 1
- 18
- 30
PHP and C++ may look similar on the surface (they share a lot of lexical elements and quite a bit of syntax), but they are two very different languages. The type systems are different (C++ arrays and PHP arrays are not the same thing), the toolkits are different, etc.
Start at the beginning.

- 119,563
- 19
- 122
- 198