Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103805 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42423 invoked from network); 23 Jan 2019 19:41:32 -0000 Received: from unknown (HELO 28.ip-149-56-142.net) (149.56.142.28) by pb1.pair.com with SMTP; 23 Jan 2019 19:41:32 -0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: thruska@cubiclesoft.com) with ESMTPSA id 0F83A3E87F To: Girgias , internals@lists.php.net References: Message-ID: Date: Wed, 23 Jan 2019 09:19:24 -0700 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Deprecation ideas for PHP 8 From: thruska@cubiclesoft.com (Thomas Hruska) On 1/22/2019 1:34 PM, Girgias wrote: > Greetings PHP internals, > After skimming through the PHP documentation, I came up with a list of > functions which seem > reasonable to deprecate as of PHP 8 and I would like to gather some > opinions from Internals. > If this seems like it's too early or should be in an RFC draft please let > me know and in case it > needs an RFC may I have Karma to do so. > Without further ado here is the list I compiled: I've run a set of searches against GitHub code repos. The numbers below are just generic metrics of usage and reloading search result pages caused result counts to vary extremely widely. I didn't look too in-depth at each result set beyond getting a number and a general feel. > PHP Info/Option functions: > > - php_sapi_name (use PHP_SAPI constant) https://github.com/search?l=PHP&o=desc&q=php_sapi_name&s=indexed&type=Code https://github.com/search?l=PHP&o=desc&q=PHP_SAPI&s=indexed&type=Code 1.02 million vs. 2.0 million code references. Both in active use. > - phpversion (use PHP_VERSION constant) https://github.com/search?l=PHP&o=desc&q=phpversion&s=indexed&type=Code https://github.com/search?l=PHP&o=desc&q=PHP_VERSION&s=indexed&type=Code 2.78 million vs. 5.1 million* code references. * Unfortunately, WordPress uses a variable called $php_version, which throws off the global count. WordPress itself uses phpversion(). That's 30% of all websites. > - php_uname (use PHP_OS constant) No. PHP_OS only covers one option that php_uname() exposes. Simple searches are turning up plenty of other php_uname() options in use. > Classes/Objects functions: > > - is_a (use instanceof operator) https://github.com/search?l=PHP&o=desc&q=is_a&s=indexed&type=Code https://github.com/search?l=PHP&o=desc&q=instanceof&s=indexed&type=Code 1.7 million vs. 28.4 million results. is_a() is still seeing some use but most people are using instanceof. Also, $allow_string describes "This also prevents from calling autoloader if the class doesn't exist." No equivalent functionality exists without this function. > - is_subclass_of (not exactly what it's purpose is but the instanceof > operator SHOULD be a valid equivalence with another condition if the same > class must not be used) https://github.com/search?l=PHP&o=desc&q=is_subclass_of&s=indexed&type=Code 1.54 million results. In addition to the notes above about is_a(), CodeIgniter appears to use this function. > Function handling functions: > > - call_user_func (invoke directly) https://github.com/search?l=PHP&o=desc&q=call_user_func&s=indexed&type=Code 10 million results. Broad, active usage. Also, there are scenarios where you can't always invoke directly as you claim. Been there, done that myself. > - call_user_func_array (arguments can be provided with the splat > operator (...) as of PHP 5.6 https://github.com/search?l=PHP&o=desc&q=call_user_func_array&s=indexed&type=Code 11.4 million results (and breaks GitHub search for me in a unique way I've not seen before). Broad, active usage. See above. > - forward_static_call (same reason as call_user_func) https://github.com/search?l=PHP&o=desc&q=forward_static_call&s=indexed&type=Code 52,200 results. Can probably be deprecated. > - forward_static_call_array (same reason as call_user_func_array) https://github.com/search?l=PHP&o=desc&q=forward_static_call_array&s=indexed&type=Code 14,581 results. Can probably be deprecated. > - func_get_arg (seems unnecessary as of PHP 5.6 with variadic functions > (splat operator)) https://github.com/search?l=PHP&o=desc&q=func_get_arg&s=indexed&type=Code 1.1 million results. While I personally never saw the point of this function since func_get_args() exists, func_get_arg() sees regular use. > - func_get_args (same reason as func_get_arg) https://github.com/search?l=PHP&o=desc&q=func_get_args&s=indexed&type=Code 9.2 million results. Oh, and the first search result that turned up for me looks fun: https://github.com/phonetworks/graphjs-server/blob/94d4a672e12a3b0b7626d8c74110b72f44d564c7/src/GraphJS/Router.php self::initSession(...\func_get_args()); An elegant (and yet slightly horrifying) one-liner crushes whatever argument you seemed to have about the splat operator: The author used both. > - func_num_args (same reason as func_get_arg) https://github.com/search?l=PHP&o=desc&q=func_num_args&s=indexed&type=Code 3.35 million results. > Variable handling functions: > Aliases: > > - is_double https://github.com/search?l=PHP&o=desc&q=is_double&s=indexed&type=Code 345,700 results. Seems to be used for unit testing code bits verifying return types. > - is_integer https://github.com/search?l=PHP&o=desc&q=is_integer&s=indexed&type=Code 1 million results. > - is_long https://github.com/search?l=PHP&o=desc&q=is_long&s=indexed&type=Code 95,400 results. > - is_real (already in the deprecation draft for PHP 7.4) https://github.com/search?l=PHP&o=desc&q=is_real&s=indexed&type=Code 54,364 results. But not even the first page of results for me shows a single call to it. Can be deprecated. > Setting var type (can use variable casting nowadays): > > - boolval https://github.com/search?l=PHP&o=desc&q=boolval&s=indexed&type=Code 54,400 results. > - doubleval https://github.com/search?l=PHP&o=desc&q=doubleval&s=indexed&type=Code 214,200 results. > - floatval https://github.com/search?l=PHP&o=desc&q=floatval&s=indexed&type=Code 1.7 million results. > - intval (for arbitrary base change there exists the math function > base_convert) https://github.com/search?l=PHP&o=desc&q=intval&s=indexed&type=Code 13.65 million results. > - strval https://github.com/search?l=PHP&o=desc&q=strval&s=indexed&type=Code 2.4 million results. I'm not in favor of removal of these functions. While *I* don't use them, lots of people still use them in conjunction with array_map() and similar callback-oriented functions. I'd rather see them be optimized within specific contexts such as array_map() for significantly improved performance *first* before recommending deprecation. > - settype https://github.com/search?l=PHP&o=desc&q=settype&s=indexed&type=Code 4.1 million results. However, most results seem to be classes with a method called setType(), so those throw off an accurate global count. There is an interesting usage here: https://github.com/isaiassm/treinaweb-laravel-blade/blob/576448cd6a061b42c4742f490e2d771b5bd127b2/vendor/phpunit/phpunit/src/Util/Xml.php \settype($variable, $element->tagName); Which I assume is for something like deserialization from XML. > - gettype (more on this later [1]) https://github.com/search?l=PHP&o=desc&q=gettype&s=indexed&type=Code 9.3 million results. However, most results seem to be classes with a method called getType(), so those again throw off an accurate global count. > String functions aliases: > > - chop (alias of rtrim) https://github.com/search?l=PHP&o=desc&q=chop&s=indexed&type=Code 562,200 results. Mostly comments about chopping up strings using substr(). Found a few legitimate usages such as Parsedown. > - join (alias of implode) Impossible to determine. JOIN in SQL is severely skewing results. > - strchr (alias of strstr) https://github.com/search?l=PHP&o=desc&q=strchr&s=indexed&type=Code 104,600 results. > Maths functions aliases: > > - getrandmax Shouldn't that have a comment like "(use mt_getrandmax() instead)"? > - rand (use mt_rand instead) > - srand (alias of mt_srand as of PHP 7.1) Most usages from searches seem to be using the mt_...() functions already anyway. > Filesystem aliases: > > - diskfreespace — Alias of disk_free_space https://github.com/search?l=PHP&o=desc&q=diskfreespace&s=indexed&type=Code 17,400 results. Can probably be deprecated. > - fputs — Alias of fwrite https://github.com/search?l=PHP&o=desc&q=fputs&s=indexed&type=Code 1.2 million results. Seems to be in active use. > - is_writeable — Alias of is_writable https://github.com/search?l=PHP&o=desc&q=is_writeable&s=indexed&type=Code https://github.com/search?l=PHP&o=desc&q=is_writable&s=indexed&type=Code 629,500 vs. 3.65 million results. (On Google: 1.19 million vs. 6.2 million results for the words writeable vs. writable.) Deprecating this alias seems petty. Users currently don't have to look up the function at the moment. Removing the alias will cause EVERYONE to look up the function to be sure they remember how to correctly spell it to avoid the deprecation warning. > - set_file_buffer — Alias of stream_set_write_buffer https://github.com/search?l=PHP&o=desc&q=set_file_buffer&s=indexed&type=Code https://github.com/search?l=PHP&o=desc&q=stream_set_write_buffer&s=indexed&type=Code 15,700 vs. 61,100 results. Of the 15,700 results, I see only a couple of function usages in the first few pages of results. Can probably be deprecated. > Old signatures: > > - implode (historical signature) Impossible to run a search for this. > Controversial idea: > > - deprecate array function creation (array()) https://github.com/search?l=PHP&o=desc&q=array&s=indexed&type=Code 71.1 million results. No. Also, array() is not a function. It's a keyword with performance on-par with []. http://php.net/manual/en/reserved.keywords.php I also prefer array() over []. It's more readable because it uses a *word* rather than unsearchable symbols to define a structure. Also, I get that arrays not actually implemented as such behind the scenes but you simply can't deprecate an estimated 70 million lines of code globally (and that's the code you can see, not including internal software everywhere). "Hi, for PHP 8, we are going to fill your hard drives via your application logs with deprecation warnings and crash your servers. Have fun sorting that mess out!" Finally, barring a serious security vulnerability, keywords should be viewed as permanent fixtures of the language. They can't be deprecated. That's why there are so few keywords. Far too much userland code will unnecessarily break. You suggest deprecating 'array' but not 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile'. All of those have alternative "shortcuts" but you didn't mention deprecating those keywords even though there is far less usage compared to 'array'. > Just to remind these are only ideas and feedback is wholeheartedly > welcomed. I also probably > missed some more functions which could be deprecated as of PHP 8 but I feel > this covers > already a large portion. > > Best regards > > George P. Banyard -- Thomas Hruska CubicleSoft President I've got great, time saving software that you will find useful. http://cubiclesoft.com/ And once you find my software useful: http://cubiclesoft.com/donate/