Protect against non-arrays when fetching headers
authorChad Horohoe <chadh@wikimedia.org>
Tue, 17 Sep 2013 01:10:47 +0000 (18:10 -0700)
committerChad Horohoe <chadh@wikimedia.org>
Tue, 17 Sep 2013 17:38:14 +0000 (10:38 -0700)
PHP documentation says this can theoretically return false on failure.

HHVM actually returns null when running from the command line, so
this does protect against that.

Change-Id: I0d75b8ed209128a9667ce1e7189597ae9ebc8af6

includes/WebRequest.php

index 55bddfc..23eee04 100644 (file)
@@ -881,8 +881,9 @@ class WebRequest {
                        return;
                }
 
-               if ( function_exists( 'apache_request_headers' ) ) {
-                       foreach ( apache_request_headers() as $tempName => $tempValue ) {
+               $apacheHeaders = function_exists( 'apache_request_headers' ) ? apache_request_headers() : false;
+               if ( $apacheHeaders ) {
+                       foreach ( $apacheHeaders as $tempName => $tempValue ) {
                                $this->headers[strtoupper( $tempName )] = $tempValue;
                        }
                } else {