WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 6 years ago

#27729 closed defect (bug) (wontfix)

error when wordpress is installed in separate directory then started in site root from function

Reported by: helened Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: Bootstrap/Load Keywords: close
Focuses: Cc:

Description (last modified by SergeyBiryukov)

When wordpress is installed in it's own directory and is started within a function in "index.php" in site root, these errors occur:

This fatal error occurs in WP 3.8.1:
[08-Apr-2014 19:34:50 UTC] PHP Fatal error: Call to a member function main() on a non-object in .../mywordpress/wp-includes/functions.php on line 808

In WP 3.9-beta3, the error changes to this non-fatal error:
[08-Apr-2014 19:53:51 UTC] PHP Warning: in_array() expects parameter 2 to be array, null given in .../mywordpress/wp-includes/kses.php on line 1176

Code samples:
index.php (no error):

   <?php require("mywordpress/index.php");?>

index.php (error):

<?php
    function site_startup(){
	     require("mywordpress/index.php");
    }
    site_startup();
    exit;
?>

Tested with PHP 5.4 on Windows (PC XAMPP server) and Linux (Bluehost.com server).

Change History (5)

#1 @jesin
7 years ago

Hi Helened,

Why are you trying to include this file inside the function? Doing this will make WordPress execute like this -

function site_startup() {
    //Entire WordPress code
}

That means the entire scope of WordPress will come into this function.

From the discussion on PHP's require() documentation page - http://www.php.net/manual/en/function.require.php#87191

require executes the code "as if" it was code written inside of the function, inheriting everything including the scope.

#2 @SergeyBiryukov
7 years ago

  • Description modified (diff)
Last edited 7 years ago by SergeyBiryukov (previous) (diff)

#3 @SergeyBiryukov
7 years ago

  • Component changed from General to Bootstrap/Load

#4 @chriscct7
6 years ago

  • Keywords close added

#5 @swissspidy
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.