Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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.


Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}