Make WordPress Core

Opened 9 years ago

Closed 9 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 (3)

#1 @wonderboymusic
9 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 'require_once( "wp-config.php" ); (PHP code goes here)'

Run that in whatever directory WordPress is in.

Last edited 9 years ago by wonderboymusic (previous) (diff)

#2 @omarabid
9 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.