Invest in the Caribbean
Enjoy the skies, the water, the views.


Real Estate &
Accommodation:
from affordable to luxury

Caribation logo for rentals and real estate

Caribation. The sunny side of your life.

Bungalow for rent


Bookmark Caribation: Ctrl-D


National flag Dominican RepublicEmergency phones
Dominican Republic
Ambulance 809-532 0000
Fire Brigade:
Santo Domingo 809-682 2000
Boca Chica 809-523 4626
Puerto Plata 809-586 2312
Police:
Santo Domingo 809-682 2151
Puerto Plata 809-586 2331
National flag CubaEmergency phones Cuba
Ambulance (Havana)
838 1185
838 2185
Fire Brigade: 105
Police: 106
Drug Unit: 103


Home | About us | Contact  English English

Palma Real

Test, then upgrade PHP version
How to do it safely?

 

Caribation Labs reports


Caribation Service for Web Developers

How to test new PHP version before running an upgrade?


This is the first question of every IT-Manager: This new version is fantastic, but will my old code run on it? Caribation Labs develops webs for the future and constantly upgrades its LAMP environment. Here we share some basic experience in testing PHP scripts for upwards compatibility.

Let us start with two common questions:

Can I test two PHP Versions within the same .php script?
NO.

Can I run two PHP Versions within the same directory?
YES.

Creating test environment

In order to have two PHP versions (for example 5.2 and 5.3) available in the same directory you need to edit .htaccess file located in this directory. Supposing your current version executing .php scripts is 5.2.17 and you want to try if a script or a group of scripts, classes or functions would run under 5.3.

Exercise 1:
Add these two lines to the .htaccess file

.htaccess
Action application/x-hg-php53 /cgi-sys/php53
AddHandler application/x-hg-php53 .php53


You have just told the Apache Server to process scripts which carry the extension .php53 (mytest.php53 for example) with PHP 5.3. You have told nothing about your other .php scripts (the default), so all standard .php files will be processed by any older PHP version you might have installed, for example by 5.2.17.

Caution:
The parameters for the Action and AddHandler statements vary from server to server. We are hosting our webs at HostGator and the examples shown here are real, but you must check with your hoster the exact syntax to be used. The extention name (.php53 in this example), however, is always up to you to choose.

Testing two PHP versions

Exercise 2:
Create a php script with the code you want to test and save it twice: as .php and .php53, for example as mytest.php and mytest.php53. The script may include an existing class, of course. For the test purpose you just need absolutely the same script but under two different names. For a quick start you can use this chunk of code:

mytest.php
<?php
namespace my53;
echo 'Hallo El Caribe';
?>
mytest.php53
<?php
namespace my53;
echo 'Hallo El Caribe';
?>

The results: easy to guess

As you have probably guessed by now, running the mytest.php will result in an error:

Parse error: syntax error, unexpected T_STRING
(if you still run 5.2). That's because namespaces were unknown to PHP prior to 5.3.

On the other hand, mytest.php53 will execute correctly because it will be processed by PHP 5.3



What do you think? Space for your experience, remarks, questions...


Trying mash-up on the topics

     Found on Google News (php,version,test)

Tue, 26 Dec 2023
Set up GitHub Actions for Laravel applications  Laravel News
Tue, 18 Jul 2023
WordPress Playground lets you run WordPress entirely in your browser  TechCrunch
Tue, 27 Dec 2022
How to Install PHP on Windows 10 and 11 (with Apache & MySQL)  SitePoint



PHP Manual






Caribation Labs for the future of your web success

Atlantic Villa in the Dom Rep

Villa with ocean view $350 000

caribbean apartment with ocean view

Apartment with Ocean View for rent in a beach area

To the girls

red heart club

Caribation succeeds with Huawei Technology!