How to switch from a C/C++ mentality to a PHP one?

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
Giganitris
Forum Newbie
Posts: 4
Joined: Fri Sep 02, 2016 7:41 pm

How to switch from a C/C++ mentality to a PHP one?

Post by Giganitris »

I don't know if this belongs in this section, I'm sorry if this should be in another subforum. Anyhow, I'm a C guy, and writing PHP is a struggle, because it requires such a huge shift in mentality. I don't really know what more to say. I'm going to look more into the reference and watch a few tutorials but damn, I'm so used to being given a small amount of tools in a library and using that to build bigger tools. Any advice or help?
hybris
Forum Contributor
Posts: 172
Joined: Wed Sep 25, 2013 4:09 am

Re: How to switch from a C/C++ mentality to a PHP one?

Post by hybris »

If it's any help there are tools for PHP too...

It took me 2 weeks to shift to PHP.
Sometimes I do get stuck and then I come here and the mods here are awesome!

I really like PHP now, I think its easy to model stuff fast using php/html...not so much code to get some visual results so atleast for me I get "feedback" faster from the code i make than in c and thats nice.

I started by doing a secure login (there is an excellent tutorial on the net for that) and when I was done with that I already gotten the feel for the language (that is if you dont just copy and paste the code :) but actually type it and try to figure out what you do).

Good luck :)

EDIT: Check AJAX, JQUERY for tools

http://www.wikihow.com/Create-a-Secure- ... -and-MySQL
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to switch from a C/C++ mentality to a PHP one?

Post by Christopher »

I think a C/C++ mentality will server you well with PHP. Plus the languages are very similar. Some of the big things you will need to change in your head are:

- No pointers. There references, but they are rarely used. And you don't allocate and free memory (don't try -- it only makes things worse).

- Scripting languages use include/autoload instead of header files, make, compile

- PHP scripts are short lived programs, so you need to adjust to the reality of building everything up per request and not freeing anything

- Shared nothing takes a little getting used to. As short lived programs, you reload the context/session each request. Yes weird, but it can be beautiful.

- The fact that PHP is mainly a HTML/CSS/Javascript generator means those languages are just as important to you as PHP.

- You can use Composer for your "small amount of tools in a library and using that to build bigger tools" approach.

There are more I am missing, but hopefully that gives you some ideas.
(#10850)
Post Reply