Each version of PHP brings with it certain deprecations. See below for a list of popular ones up until PHP 7.2.
// Deprecated
split(',', $foo);
// Substitute
preg_split('/,/', $foo);
// Deprecated
uasort($list,
create_function('$a, $b',
'return $a->getName()>$b->getName();'
)
);
// Substitute
uasort($list, function ($a, $b) {
return $a->getName() > $b->getName();
});
// Deprecated
while(list($key, $val) = each($data)) {
}
// Substitute
foreach ($data as $key => $val) {
}
// Deprecated
preg_replace('/href="(.*?)"/ie',
"foo('$link', '\\1', '$eid', '$id')",
$string
);
// Substitute
preg_replace_callback('/href="(.*?)"/i', function ($matches) use ($link, $eid, $id) {
return foo($link, $matches[1], $eid, $id);
}, $string);
// Deprecated
ereg("^foobarbaz", $filename);
// Substitute
preg_match('/^foobarbaz/', $filename);
// Deprecated
eregi("^FooBarBaz", $filename);
// Substitute
preg_match('/^FooBarBaz/i', $filename);
// Deprecated
ereg_replace(',,', ',', $foo);
// Substitute
preg_replace('/,,/', ',', $foo);
Deprecated | Substitute |
---|---|
$HTTP_RAW_POST_DATA | php://input |
$HTTP_SESSION_VARS | $_SESSION |
$HTTP_SERVER_VARS | $_SERVER |
$HTTP_POST_VARS | $_POST |
$HTTP_GET_VARS | $_GET |
$HTTP_ENV_VARS | $_ENV |
$HTTP_COOKIE_VARS | $_COOKIE |
// Deprecated
ini_set('track_errors', 1);
echo $php_errormsg;
// Substitute
echo error_get_last()['message']
These will be evaluated strictly in left-to-right order since PHP 7.0. Use curly braces to remove ambiguity.
// Change code like this...
$data = $model->$field['function']();
// ...to this
$data = $model->{$field['function']}();
// Deprecated
$a = parse_str($q);
// Substitute
parse_str($q, $a);
// Deprecated
if (!session_is_registered('userid')) {
}
// Substitute
if (!$_SESSION['userid']) {
}
// Deprecated
function __autoload($classname) {
require_once(strtolower($classname) . '.class.php');
}
// Substitute
spl_autoload_register(function ($classname) {
require_once(strtolower($classname) . '.class.php');
});
// Deprecated
class Foo
{
public function Foo()
{
// constructor
}
}
// Substitute
class Foo
{
public function __construct()
{
// constructor
}
}