David-London Posted December 11, 2021 Share Posted December 11, 2021 I have upgraded to PHP8.o and have a plugin using the depreciated each() function. Would this be a correct refactor of this code? -- see the inline comments where I have made the changes // get the importable types $types = $this -> get_importable_post_types(); settype($types, 'array'); // I added this line if ( ! $types ) : _e('Sorry, there are no public post types that support post thumbnails.', 'plugin_default'); return; endif; _e('The default post type for new posts will be ', 'plugin_default'); if ( count($types) == 1 ): // only one so no need for selector // list($post_type, $post_type_name) = each($types); // I have taken this line out $post_type = key($types); // I added this line $post_type_name = current($types); // I added this line ?> Thanks for your help Quote Link to comment Share on other sites More sharing options...
ginerjm Posted December 11, 2021 Share Posted December 11, 2021 (edited) This seems to work for me: list($fld1,$fld2,$fld3) = array_values($arr); And PS - the word is deprecated, not depreciated. No ' i '. Two entirely different meanings. Edited December 11, 2021 by ginerjm Quote Link to comment Share on other sites More sharing options...
requinix Posted December 11, 2021 Share Posted December 11, 2021 Given that $types has only one entry in it, yes: using key() and current() is a good solution in practice. It wouldn't work if something was iterating over $types using next(), but that is very likely not happening. Quote Link to comment Share on other sites More sharing options...
David-London Posted December 13, 2021 Author Share Posted December 13, 2021 Thanks for your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.