-
Notifications
You must be signed in to change notification settings - Fork 0
PHP Upgrades
Hunter Wu edited this page Mar 18, 2019
·
2 revisions
~/.composer/vendor/bin/phpcs -s --standard=PHPCompatibility --extensions=php,inc,phtml .
// php5
function camelize($word) {
return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word);
}
// php7
function camelize_callback($matches) {
return strtoupper($matches[2]);
}
function camelize($word) {
return preg_replace_callback('/(^|_)([a-z])/', 'camelize_callback', $word);
}
echo camelize("_hello _world _123 _abc"), "\n\n";
$str = '@'; // @
if (PHP_VERSION < 7) {
$result = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str);
} else {
$result = preg_replace_callback('~&#x(0*[0-9a-f]{2,5})~i', function($matches) {
return chr(hexdec($matches[1]));
}, $str);
}
echo $result, "\n";
Indirect access to variables, properties and methods will be evaluated strictly in left-to-right order since PHP 7.0
// php5
return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this);
// php7
return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->{$function[1]}($new_args, $this);
// php5
$$setting['variable'] = $setting['value'];
// php7
${$setting['variable']} = $setting['value'];
The behaviour of hexadecimal numeric strings was inconsistent prior to PHP 7 and support has been removed in PHP 7.
// php5
'0x42'
// php7
0x42