Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#21971 closed enhancement (invalid)

Checking for Server Protocol causes PHP notices

Reported by: omarabid Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.4.2
Component: Warnings/Notices Keywords:
Focuses: Cc:


I'm debugging my WordPress App. through the PHPStorm Debugger which is not a Browser but a simple compiler of the PHP code.

WordPress checks for two global variables without checking that they are defined, which causes an annoying notice in the Debugger.

The file: wp-includes/functions.php

The function: status_header()

The solution is simply to check that the variable is defined

    if (isset($_SERVER["SERVER_PROTOCOL"])) {
        $protocol = $_SERVER["SERVER_PROTOCOL"];
    } else {
        $protocol = null;

The same problem for the function redirect_canonical().

A simple isset() check will get rid of this annoyance.

Change History (2)

#1 @wonderboymusic
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

WordPress is not meant to run on the command line (as a PHP binary app which is what PHP Storm is doing) as is - anytime you run WordPress as a php app versus in the browser, $_SERVER won't be set properly. If you want to run WordPress on the command line without loading queries or the theme:

php -r 'wp-config.php'

Run that in whatever directory WordPress is in.

Version 0, edited 3 years ago by wonderboymusic (next)

#2 @omarabid
3 years ago

I need to load both the Theme and the Queries. I got around it (if anyone is looking for a solution) by creating a prepend.php and adding auto_prepend_file = "prepend.php" to the PHP.ini. The file obviously sets these variables to mimic a web server.

However, isn't it a best practice to check that variables are defined before using them?

Note: See TracTickets for help on using tickets.