Title: Undefined array key &#8220;SCRIPT_FILENAME&#8221;
Last modified: April 20, 2022

---

# Undefined array key “SCRIPT_FILENAME”

 *  Resolved [KevinPlusPlus](https://wordpress.org/support/users/kevinplusplus/)
 * (@kevinplusplus)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/undefined-array-key-script_filename/)
 * Hello,
 * I have my WP Cron executed using PHP rather than the web server, and this causes
   the following warning in PHP 8.1:
 * Undefined array key “SCRIPT_FILENAME” in /tablepress/classes/class-tablepress.
   php on line 110
 * The problem is: ‘wp-login.php’ === basename( $_SERVER[‘SCRIPT_FILENAME’] )
 * The code there already checks for DOING_CRON, but that check occurs AFTER the
   check against the _SERVER[‘SCRIPT_FILENAME’]
 * This can be fixed simply by re-ordering the “or” conditions to check for CRON
   and XMLRPC first, and then for wp-login.php.
 * Thanks,
 * Kevin Hock

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/undefined-array-key-script_filename/#post-15576159)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * That sounds strange. Why isn’t `$_SERVER['SCRIPT_FILENAME']` set here? From everything
   I can see, it should also be set if a script is called via the CLI or a cron 
   job?
 * To be honest, I’m not a big fan of using reordering of if checks here, as it 
   feels like this would only “hide” an actual underlying issue.
 * Regards,
    Tobias
 *  Thread Starter [KevinPlusPlus](https://wordpress.org/support/users/kevinplusplus/)
 * (@kevinplusplus)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/undefined-array-key-script_filename/#post-15576225)
 * Tobias,
 * I have been reading about this and it seems that SCRIPT_FILENAME may not always
   be set. For example: [https://www.php.net/manual/en/reserved.variables.server.php](https://www.php.net/manual/en/reserved.variables.server.php)
 * Data: $_SERVER[‘SCRIPT_FILENAME’]
    Data type: String Purpose: The absolute pathname
   of the origin PHP file, including the filename Caveat: Not set on all PHP environments,
   may need setting by copying from __FILE__ before other files are included.
 * I did some additional testing and this is unique to running from a cron job. 
   If I run from the command line:
 * php [full path removed for security]/wp-cron.php
 * there is no warning. Run the same commandnd run from the cron job does generate
   the warning. It seems that this just a quirk of how the PHP job is spawned, perhaps
   because of running as root for the cron job?
 * I don’t see any harm in re-arranging the order, the checks accomplish exactly
   the same thing and prevents a warning on this border case. PHP 8 is very strict
   about accessing non-existing array elements. If you are reluctant to re-order
   them, how about checking if the array index exists before accessing it, which
   is a better programming practice especially under PHP 8.
 * ( isset($_SERVER[‘SCRIPT_FILENAME’]) && ‘wp-login.php’ === basename( $_SERVER[‘
   SCRIPT_FILENAME’] ) )
 * Thanks,
 * Kevin
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/undefined-array-key-script_filename/#post-15576248)
 * Hi,
 * thanks for looking into this some more! Really weird indeed.
 * I would then lean towards that `isset()` check. That’s what WordPress Core also
   seems to be doing in 2-3 places.
 * Thanks for bringing this up!
 * Regards,
    Tobias
 *  Thread Starter [KevinPlusPlus](https://wordpress.org/support/users/kevinplusplus/)
 * (@kevinplusplus)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/undefined-array-key-script_filename/#post-15576254)
 * Tobias,
 * Yes, it is a strange one. Thanks for your help!
 * Kevin
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/undefined-array-key-script_filename/#post-15576310)
 * Hi,
 * sure, no problem!
 * Best wishes,
    Tobias   P.S.: In case you haven’t, please rate TablePress [here](https://wordpress.org/support/plugin/tablepress/reviews/#new-post)
   in the plugin directory. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Undefined array key “SCRIPT_FILENAME”’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [3 years, 11 months ago](https://wordpress.org/support/topic/undefined-array-key-script_filename/#post-15576310)
 * Status: resolved