SunshinePHP 2016

PHP 5.3.x で推奨されない機能

PHP 5.3.0 では新しく二つのエラーレベルが加わりました。 E_DEPRECATEDE_USER_DEPRECATED です。 E_DEPRECATED エラーレベルは、 特定の機能が推奨されないことを示すのに使います。 E_USER_DEPRECATED エラーレベルは、ユーザー定義のコードで推奨されない機能、たとえば E_USER_ERRORE_USER_WARNING のようなものを示すのに使います。

INI ディレクティブで推奨されないものは以下の通りです。 これらのひとつ以上を有効にすると、起動時 E_DEPRECATED エラーが発生します



  • new の返り値を参照で代入すること
  • 呼び出し時の参照渡し
add a note add a note

User Contributed Notes 3 notes

shad at shartley dot net
5 years ago
Correction on my previous note.

sed -i 's/\$HTTP_\(.*\)_VARS/\$_\1/g' {} \;

will screw up multiple instances of $HTTP_*_VARS in the file.

You'll have to use an instance of sed like:

sed -i 's/\$HTTP_SERVER_VARS/\$_SERVER/g'
find ./ -name "*.php" -exec sed -i 's/\$HTTP_POST_VARS/\$_POST/g' {} \;
find ./ -name "*.php" -exec sed -i 's/\$HTTP_GET_VARS/\$_GET/g' {} \;

for each of the deprecated variables you might have in your files.

It also occurred to me a simple php conversion script would also work:


add directory recursion functions, ect.
5 years ago
A backward compatibility break which is not documented:

Fatal error: Uncaught exception 'RuntimeException' with message 'Directory name must not be empty.'

This happens with new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $staticPath ) )
shad at shartley dot net
5 years ago
If you previously defined register_long_arrays in php.ini and have a lot of code with $HTTP_*_VARS that need to be replaced the following may help on *.nix systems:

sed -i 's/\$HTTP_\(.*\)_VARS/\$_\1/g' filename.php

What this command does is replace all occurrences of $HTTP_*_VARS with their respective $_ counter parts, e.g. $HTTP_COOKIES_VAR to $_COOKIES

To replace alot of files, you might combine it with the find command: 
find ./ -name "*.php" -exec sed -i 's/\$HTTP_\(.*\)_VARS/\$_\1/g' {} \;

For other deprecated variables like $HTTP_POST_FILES change your sed arguments:

sed -i 's/\$HTTP_POST_FILES/\$_FILES/g'

Deprecated variables created by the register_long_arrays directive as far as I know are:
To Top