I’ve completely taken over my company’s site and the old developers used PHP5 file extensions. I’ve worked with them for a while, but then wondered why? I’m still somewhat new to PHP, but when I renamed every file from GoDaddy and openned them on my localhost on Ubuntu, the pages loaded normal. So why in the world did the developers use php5 file extensions?
Also to mention, they used bad ways of coding I found out like
<?= $code ?> when they should have used
<?php echo $code; ?>.
Will I be safe moving the renamed php file extensions over and renaming the “ipn.php5” to “ipn.php” for PayPal?
I know .php5 is a new version and not language, so what’s the point of using .php5 file extensions when I can do all that I want with .php file extensions?
The file extension tells the web server which version of PHP to use. Some web servers are set up so that PHP 4 is the default, and you have to use
.php5 to tell it to use PHP 5. More and more web servers these days are set up so that
.php defaults to PHP 5, and the
.php5 extension doesn’t do anything extra.
In fact, if you have control over the web server you should be able to configure the mapping between file extensions and PHP versions whichever way you want. On shared hosting providers the mapping can’t be changed without affecting other users of the same server.
.php extension gives you the version of PHP that you require, then go for it. It’s best to keep it consistent across your entire project, however.
It’s usually done so they can run two version of the PHP interpreter on the server and the Apache to parse .php5 files with the PHP 5.x interpreter and .php files with an older PHP 4.x interpreter.
You’d have to check your Apache config to see if this is the case. If this is the case you’d then have to change the config to parse .php files through the PHP 5.x interpreter before renaming the file extension.
Then run the app through it’s paces keeping an eye on the error log for new error/notices. I had a similiar experience and found out I had to convert all instance of ereg (which is deprecated in PHP 5) to preg_match.
This may not be why the developers used the php5 extension, but here is one instance that I have found where it is helpful. The files in my project use PHP in two distinct ways (1) as preprocessor tags inside a predominantly HTML file (or any other type of file for that matter), and (2) as a language where files are predominantly PHP code with echo statements to output HTML (or anything else for that matter).
In my project, the two types of uses (done at different times by different teams) are flagged by using the two different extensions. This allows conveniences like: easy sorting in a GUI file manager or version control system; HTML targetted syntax highlighting for (1) and PHP highlighting for (2) in most editors; simpler automation of continuous integration tasks such as testing, linting….
Whether done on purpose or not, in many legacy projects, file extensions can give clues about when and why files were created, and I don’t destroy these clues without a good reason.