• Resolved Franky

    (@liedekef)


    The following notice gets triggered by mainwp:
    PHP Notice: Only variables should be passed by reference in /var/www/html/wordpress/wp-content/plugins/mainwp/class/class-mainwp-utility.php on line 923

    The relevant line is in the function check_image_file_name:
    $file_ext = strtolower( end( explode( '.', $filename ) ) );
    The “end” call triggers this (since it passes arrays by reference). The best methods to have the last element in an array are:

    1) $x = array_values(array_slice($array, -1))[0]; as the most generic and fast solution
    2) $x = $array[count($array)-1]; for auto-indexed arrays
    3) $x = $array[array_key_last($array)]; is the preferred and fastest method since php 7.3 (function array_key_last doesn’t exist before that)

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP notice: Only variables should be passed by reference’ is closed to new replies.