Over a million developers have joined DZone.

Avoid legacy programming practices in PHP 5.4: the underscore lesson from PHP4/5

DZone's Guide to

Avoid legacy programming practices in PHP 5.4: the underscore lesson from PHP4/5

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

Old habits die hard; old language habits die harder; old programming habits die hardest, especially when the habit first developed from a defect in the language.

So as PHP5.4 approaches, it's a good idea to take stock of the habits you may have developed in previous versions of PHP.

Volker Dusch addresses one of these habits: the 'privatizing underscore', an old dodge designed to keep variables private in the programmer's head -- because PHP4 couldn't keep variables private on its own.

PHP 5 offeredprivate variables, so nobody really needed underscores anymore. But plenty of apps were still written in PHP4; and, besides, lots of coders were used to those underscores, so they kept on using them anyway.

But now PHP4 has mostly disappeared. It's to act like it's gone, declares Volker:

We are deep into 5.x now and it’s time to get rid of your PHP 4 legacy. The last release was 3 years ago, the number of people that still admit to using it in production dropped below the care ratio and all major frameworks and libs migrated.

The real point is that retaining legacy programming practices past due date can only lead to rotten code. (For example, what if you need to make a variable public? 'Replace all in project'?)

Volker's sage advice is: every new language release is an opportunity to move on. But, more specifically, stop talking in underscores to PHP4 users that no longer exist.

Read the rest of his post here.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}