WordPress.org

Make WordPress Core

Opened 19 months ago

Closed 19 months ago

Last modified 19 months 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:

Description

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)

comment:1 wonderboymusic19 months 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 19 months ago by wonderboymusic (previous) (diff)

comment:2 omarabid19 months 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.