diff --git a/src/wp-includes/category.php b/src/wp-includes/category.php
index cbef474..a89b410 100644
--- a/src/wp-includes/category.php
+++ b/src/wp-includes/category.php
@@ -51,10 +51,16 @@ function get_categories( $args = '' ) {
 		$taxonomy = $args['taxonomy'] = 'link_category';
 	}
 
-	$categories = (array) get_terms( $taxonomy, $args );
+	$categories = get_terms( $taxonomy, $args );
 
-	foreach ( array_keys( $categories ) as $k )
-		_make_cat_compat( $categories[$k] );
+	if ( is_wp_error( $categories ) ) {
+		$categories = array();
+	} else {
+		$categories = (array) $categories;
+		foreach ( array_keys( $categories ) as $k ) {
+			_make_cat_compat( $categories[ $k ] );
+		}
+	}
 
 	return $categories;
 }
diff --git a/tests/phpunit/tests/category/getCategories.php b/tests/phpunit/tests/category/getCategories.php
new file mode 100644
index 0000000..3f2140d
--- /dev/null
+++ b/tests/phpunit/tests/category/getCategories.php
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * @group taxonomy
+ * @group category.php
+ */
+class Tests_Category_GetCategories extends WP_UnitTestCase {
+	/**
+	 * @ticket 36227
+	 */
+	public function test_wp_error_should_return_an_empty_array() {
+		$found = get_categories( array( 'taxonomy' => 'foo' ) );
+		$this->assertSame( array(), $found );
+	}
+}
