Migrating from Php 5 to Php 7

php 7 - next major thingPhp 7 was released in december 2015 and active support for Php 5 is given until 31 december 2016. While there will be security releases for Php 5.6 till jan 2019, it’s a smart move to look at Php 7 for your projects, because new libraries will slowly stop supporting Php 5. See the Supported Versions page of Php for the details.

If you migrate to Php 7 you will probably walk into two things,


A list of backward incompatible language changes can be found at http://php.net/manual/en/migration70.incompatible.php There are big changes in exception handling and variable handling. Especially the new method for evaluation multi-dimension array's can give tricky bugs with existing code.

Deprecated API calls which gave a E_DEPRECATED notice in Php 5 are actually removed in Php 7. These changes give fatal compile errors and are easily detected. Of course it’s better to rewrite the code using the new API, but it’s also possible to write a wrapper for these functions. If you’ve got a big project to migrate, this can save lots of time.

For handling the mysql functions, I wrote the following wrapper,

/**
* backwards compatibility old php functions
*/

if (function_exists('mysql_connect') == false) {
function mysql_connect($server, $username, $password, $new_link = false, $client_flags) {
$key = $server.$username.$password;
if (isset($GLOBALS['mysql_cons']) == false) {
$GLOBALS['mysql_cons'] = false;
}
if ($new_link == false && isset($GLOBALS['mysql_cons'][$key])) {
return $GLOBALS['mysql_cons'][$key];
}

$con = new mysqli($server, $username, $password);

if (isset($GLOBALS['mysql_cons'][$key]) == false) {
$GLOBALS['mysql_cons'][$key] = $con;
}

if (isset($GLOBALS['mysql_cons']['default']) == false) {
$GLOBALS['mysql_cons']['default'] = $con;
}

$r = $con->connect($server, $username, $password);

if ($r === false)
return false;

return $con;
}

function mysql_select_db($dbname, $con=null) {
if ($con == null) {
$con = $GLOBALS['mysql_cons']['default'];
}

$r = $con->select_db($dbname);
return $r;
}

function mysql_query($query, $con) {
if ($con == null) {
$con = $GLOBALS['mysql_cons']['default'];
}

return $con->query($query);
}

function mysql_real_escape_string($val, $con=null) {
if ($con == null) {
$con = $GLOBALS['mysql_cons']['default'];
}

return $con->escape_string($val);
}


function mysql_insert_id($con=null) {
if ($con == null) {
$con = $GLOBALS['mysql_cons']['default'];
}

return $con->insert_id;
}

function mysql_error($con=null) {
if ($con == null) {
$con = $GLOBALS['mysql_cons']['default'];
}

return $con->error;
}

function mysql_fetch_assoc($result) {
$row = $result->fetch_assoc();

return $row;
}

function mysql_fetch_array($result) {
$row = $result->fetch_array();

return $row;
}

function mysql_num_rows($result) {
return $result->num_rows;
}
}

if (function_exists('split') == false) {
function split($pattern, $string, $limit=-1) {
return preg_split('/'.$pattern.'/', $string, $limit);
}
}



- Bent u opzoek naar een Php of Java programmeur voor uw website of applicatie? (freelance / detachering)
- Losse tickets, opdrachten, of gehele projecten in de planning?
- Systeembeheer van Linux of Windows Server ?

Dan kom ik graag met u in contact! Meer informatie over mij vindt u hier.
Sitemap | Op alle producten & diensten zijn de algemene voorwaarden van toepassing
Maatwerk software Alkmaar | Maatwerk software Heerhugowaard | Maatwerk software Purmerend | Maatwerk software Zaandam | Software laten maken | Freelance php programmeur Afbouw maatwerk software Blogs