Make WordPress Core

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#54142 closed defect (bug) (fixed)

Undefined array key "SCRIPT_NAME" in wp_fix_server_vars()

Reported by: mcjambi's profile mcjambi Owned by: hellofromtonya's profile hellofromTonya
Milestone: 5.9 Priority: normal
Severity: normal Version: 2.0
Component: Bootstrap/Load Keywords: has-patch commit php8 php81
Focuses: Cc:

Description

My log file is increasing size day by day with this bug:
[16-Sep-2021 21:37:01 UTC] PHP Warning: Undefined array key "SCRIPT_NAME" in /home/rntlckly/public_html/wp-includes/load.php on line 79

---
PHP 8.x
Wordpress 5.8.1

Attachments (2)

54142.diff​ (517 bytes) - added by karpstrucking 5 years ago.
54142.1.diff​ (483 bytes) - added by audrasjb 5 years ago.
Patch refreshed against trunk for 5.9

Download all attachments as: .zip

Change History (14)

#1 @costdev
5 years ago

Hi @mcjambi,

This issue is usually related to cron jobs, or server configuration, such as when running with fastcgi, etc. ​This support thread may be relevant to you.

If you are unable to resolve the issue from that thread, please create a new thread in ​the WordPress Support forums, providing some information about your server configuration and whether this is occurring when accessing WordPress via browser or if you're using another method.

#2 @SergeyBiryukov
5 years ago

  • Component changed from General to Bootstrap/Load
  • Summary changed from Bug in wp-includes/load.php to Undefined array key "SCRIPT_NAME" in wp_fix_server_vars()
  • Version changed from 5.8.1 to 2.0

Hi there, welcome back to WordPress Trac! Thanks for the report.

It looks like this code was introduced in [3034] and adjusted in [3069]. Changing the Version field accordingly.

#3 @karpstrucking
5 years ago

  • Keywords has-patch added

#4 @SergeyBiryukov
5 years ago

  • Milestone changed from Awaiting Review to 5.9

#5 @SergeyBiryukov
5 years ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

This ticket was mentioned in ​Slack in #core by audrasjb. ​View the logs.


5 years ago

@audrasjb
5 years ago

Patch refreshed against trunk for 5.9

This ticket was mentioned in ​Slack in #core by audrasjb. ​View the logs.


4 years ago

#8 @hellofromTonya
4 years ago

  • Keywords commit added
  • Owner changed from SergeyBiryukov to hellofromTonya

Assigning to me to check behavior of the PHP native function (for PHP 8.1) and if cool, get it committed.

#9 @hellofromTonya
4 years ago

Noting: If the key doesn't exist, the error depends upon the PHP version:

  • PHP 8.0+ throws a warning
  • PHP 8.1 also throws a deprecation notice
    Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated
    
  • PHP 9 will likely be a fatal error

See it in action: ​https://3v4l.org/aJ2kX

#10 @hellofromTonya
4 years ago

  • Keywords php8 php81 added

#11 @hellofromTonya
4 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 52144:

Bootstrap/Load: Check $_SERVER['SCRIPT_NAME'] exists before passing to strpos() in wp_fix_server_vars().

If SCRIPT_NAME' does not exist (which can happen in cron jobs), the following happens:

  • PHP 8.1+:
    • Warning: Undefined array key "SCRIPT_NAME"
    • Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated
  • PHP 8.0: Warning: Undefined array key "SCRIPT_NAME"
  • PHP 5.6-7.4: No warning or notice

This commit checks if the key exists before passing it to strpos(). This resolves the warning, notice, and future error.

Follow-up to [3034], [3069], [12732].

Props audrasjb, costdev, hellofromTonya, karpstrucking, mcjambi, sergeybiryukov.
Fixes #54142.

#12 @hellofromTonya
4 years ago

Thank you everyone for contributing! This fix will ship in 5.9.

Note: See TracTickets for help on using tickets.