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
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
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
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
Tobias,
Yes, it is a strange one. Thanks for your help!
Kevin
Hi,
sure, no problem!
Best wishes,
Tobias
P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!