Php как убрать deprecated

PHP RFC: Remove deprecated functionality in PHP 7

This RFC proposes to remove functionality which has been deprecated during the 5.x cycle.

The following extensions are deprecated:

The following language features are deprecated:

The following functions are deprecated:

mcrypt_ecb , mcrypt_cbc , mcrypt_cfb and mcrypt_ofb (since PHP 5.5, but documented as deprecated earlier; use mcrypt_encrypt and mcrypt_decrypt instead) REMOVED

datefmt_set_timezone_id and IntlDateFormatter::setTimeZoneID (since PHP 5.5; use datefmt_set_timezone or IntlDateFormatter::setTimeZone instead) REMOVED

The following ini options are deprecated:

iconv.input_encoding , iconv.output_encoding , iconv.internal_encoding , mbstring.http_input , mbstring.http_output and mbstring.internal_encoding (since PHP 5.6; use php.input_encoding , php.internal_encoding and php.output_encoding instead) [TODO]

The following miscellaneous functionality is deprecated:

PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT driver option (since PHP 5.6; use PDO::ATTR_EMULATE_PREPARES instead) REMOVED

Patches and Tests

Note: Patches are very outdated. I’ll update them after the votes.

Votes

Voting started on 2015-01-02 and ended on 2015-01-16. All votes refer to PHP 7.

All removals have been accepted.

ext/ereg

The ereg extension has been deprecated since PHP 5.3. The PCRE extension should be used instead. PCRE provides better Unicode support and many more features in general. The ereg extension is effectively unmaintained currently.

If ext/ereg is removed as a bundled extension, it can still be made available as a PECL extension.

Vote: Requires simple majority.

ext/mysql

The mysql extension has been deprecated since PHP 5.5. The mysqli or PDO extension should be used instead. The deprecation has been decided in mysql_deprecation, where a discussion of the reasons behind this decision can be found.

If ext/mysql is removed as a bundled extension, it can still be made available as a PECL extension.

Vote: Requires simple majority.

Assignment of new by reference

Since PHP 5.3 assignment of new expressions by references is deprecated. It can be replaced with a normal assignment 1) :

// Instead of $obj =& new ClassName; // Write $obj = new ClassName;

Assigning the return value by reference is no longer necessary since PHP 5.0.

Читайте также:  Detect Browser in JavaScript

Vote: Requires 2/3 majority.

Scoped calls of non-static methods from incompatible $this context

Since PHP 5.5 scoped calls of non-static methods from incompatible $this contexts are deprecated, while they already generated an E_STRICT level error previously. The deprecation has been decided in incompat_ctx, where examples of this functionality can be found.

The RFC already specified that the functionality will be removed in the next version after deprecation, as such this vote may dropped.

Vote: Requires 2/3 majority.

dl() on fpm-fcgi

Use of dl() in the fpm-fcgi SAPI is deprecated since PHP 5.3.

Using the dl() function in SAPIs that run more than one request has stability concerns. As such it has already been removed from other multi-request SAPIs, fpm-fcgi is the last one left.

Vote: Requires simple majority.

set_magic_quotes_runtime() and magic_quotes_runtime()

Support for magic quotes has been removed in PHP 5.4. To facilitate backwards compatibility the set_magic_quotes_runtime() and magic_quotes_runtime() functions have been retained, but deprecated. Attempting to enable magic quotes using them will result in a fatal error.

Vote: Requires simple majority.

Other deprecated functions

The following functions are deprecated:

mcrypt_ecb , mcrypt_cbc , mcrypt_cfb and mcrypt_ofb (since PHP 5.5, but documented as deprecated earlier; use mcrypt_encrypt and mcrypt_decrypt instead)

datefmt_set_timezone_id and IntlDateFormatter::setTimeZoneID (since PHP 5.5; use datefmt_set_timezone or IntlDateFormatter::setTimeZone instead)

These functions are just legacy aliases or quasi-aliases.

Vote: Requires simple majority.

xsl.security_prefs ini directive

As a fix for CVE 2012-0057 (Bug #54446), which concerns reading and writing files using XSLT, the XsltProcessor::setSecurityPrefs() method and xsl.security_prefs ini directive have been added. The latter has been deprecated in PHP 5.4 to discourage global disabling of security features. Instead the setSecurityPrefs() method should be used on individual XsltProcessor instances where reading/writing files is necessary.

Vote: Requires simple majority.

iconv and mbstring encoding ini directives

The iconv.input_encoding , iconv.output_encoding , iconv.internal_encoding , mbstring.http_input , mbstring.http_output and mbstring.internal_encoding ini directives have been deprecated in PHP 5.6 by the default_encoding RFC . Instead the use of the more general php.input_encoding , php.internal_encoding and php.output_encoding ini directives is suggested.

Vote: Requires simple majority.

$is_dst parameter of the mktime() and gmmktime() functions

The $is_dst parameter of the mktime() and gmmktime() functions has been deprecated in PHP 5.1. Instead the timezone handling functions should be used.

Читайте также:  Работа с retrofit java

Vote: Requires simple majority.

#-style comments in ini files

The standard ini file format uses ; to denote comments. However PHP accidentially (?) also supported comments starting with # in some circumstances. When this was discovered in PHP 5.3, they were deprecated.

Vote: Requires simple majority.

String category names in setlocale()

Since PHP 5.3 the use of string category names in setlocale() is deprecated and the corresponding LC_* constants should be used instead:

// Instead of setlocale('LC_ALL', 'de_DE'); // Write setlocale(LC_ALL, 'de_DE');

Vote: Requires simple majority.

Unsafe curl file uploads

As part of the curl-file-upload RFC , the CURLOPT_SAFE_UPLOAD curl option has been introduced in PHP 5.5 to control whether the use of CURLFile is required to upload files. Since PHP 5.6 the option defaults to true .

For compatibility purposes the option will not be removed altogether, only the ability to set it to false is removed.

Vote: Requires simple majority.

preg_replace() eval modifier

Due to security considerations the remove_preg_replace_eval_modifier RFC has deprecated the /e (eval) modifier used by preg_replace() in PHP 5.5. Instead preg_replace_callback should be used.

Vote: Requires simple majority.

PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT driver option

In PHP 5.6 the pgsql specific driver option PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT was deprecated in favor of the more general PDO::ATTR_EMULATE_PREPARES option.

Vote: Requires simple majority.

CN_match and SNI_server_name stream context options

Since PHP 5.6 it is no longer necessary to explicitly specify the host name using the CN_match and SNI_server_name stream context options, it will be determined automatically instead. It is possible to manually specify a host name using the peer_name context option, which covers both CN and SNI. The old, separate options have been deprecated.

Vote: Requires simple majority.

Источник

Prevent E_DEPRECATED error messages in PHP

PHP 5.3 introduced a new error reporting level E_DEPRECATED which is triggered when deprecated functions and methods are used, such as the old style ereg() regular expression functions. This post shows how to suppress E_DEPRECATED error messages.

In PHP.ini

To show all errors other than E_DEPRECATED in the php.ini file, adjust the error_reporting setting as shown below. Note this should only be done for installs of PHP 5.3+.

error_reporting = E_ALL & ~E_DEPRECATED

To suppress notices as well:

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED

In code with error_reporting

You can either straight out set the error reporting level like so:

error_reporting(E_ALL &~ E_DEPRECATED); error_reporting(E_ALL &~ E_NOTICE &~ E_DEPRECATED);

or remove E_DEPRECATED from the current error_reporting level:

error_reporting(error_reporting() & ~E_DEPRECATED);

Making it safe for earlier versions of PHP

The only catch with the above error_reporting examples is that if you’re running the same code on e.g. PHP 5.2 as well as PHP 5.3 then you’ll get a notice in PHP 5.2 (and earlier) like «Notice: Use of undefined constant E_DEPRECATED».

Читайте также:  Set file type java

To avoid triggering this notice check if E_DEPRECATED is defined:

Development vs production

While you certainly won’t want to trigger E_DEPRECATED messages in production, you may well want to show them in development to make it easy to locate and update code with deprecated functions. (Note you can suppress the display of error messages regardless of the error_reporting level with display_errors).

In my case, I’ve been using SilverStripe 2.4 which occasionally makes use of the ereg() functions and I prefer not to have the messages displayed even in development. SS 3 will come out later this year and I’m sure they’ll have replaced the ereg functions with preg equivilents. Maybe then I’ll switch back E_DEPRECATED in development.

Источник

Disable E_DEPRECATED in php error log

When PHP runs as an Apache module, you can access/change any configuration setting available in php.ini using directives in Apache configuration files. Those directives are.

The difference between the php_* and php_admin_* versions is the key to this issue. Values set using php_admin_value and php_admin_flag can only be set in Apache global and VirtualHost configs; they are not overrideable by .htaccess or ini.set().

The error_reporting() function is equivalent to an ini_set() call, and falls under the same rules.

So I went into the virtualhost configuration for the site in question, and added the following lines.

php_admin_value error_reporting 22527 php_admin_value error_log /custom/log/path/php_errors.log php_admin_flag log_errors On php_admin_flag display_errors Off 
  1. The first line is the bitwise value for error_reporting = E_ALL & ~E_DEPRECATED . I retrieved this value by creating a simple script:
ini_set("error_reporting", E_ALL & ~E_DEPRECATED); echo ini_get("error_reporting"); 

Again, the priority and order of operations is key here. These values supersede those defined in php.ini , and at the same time cannot be overridden by other changes within the application or in .htaccess files.

More details on changing configuration values outside php.ini can be found in the PHP documentation.

Источник

Оцените статью