kayue / WordpressBundle

THIS PROJECT IS DEPRECATED AND WILL NOT BE MAINTAINED ANYMORE.
48 stars 14 forks source link

What does $returnValue in ApiLoader->load() do? #5

Closed kayue closed 12 years ago

kayue commented 12 years ago

Hi Mrtorrent

I was trying to figure out what does the following lines do in ApiLoader->load(), could you give me some hints?

$returnValue = require_once $bootstrap;

foreach (get_defined_vars() as $name => $value) {
    if ($name == 'bootstrap' or $name == 'returnValue') continue;
    $GLOBALS[$name] = $value;
}

return $returnValue;

https://github.com/kayue/WordpressBundle/blob/master/Wordpress/ApiLoader.php#L79-84

Thank you so much!

Best Ka Yue

mrtorrent commented 12 years ago

Hi Ka Yue,

The $returnValue is used to capture and pass through anything returned from the bootstrap. There isn't anything generally, but it's available just in case.

The loop over get_defined_vars() is to try and work around WordPress not explicitly globalising variables. Since WordPress assumes it is being run in the global scope, any variables it sets are implied to be global, and so we copy them to the global scope to match WordPress's expectations.

Let me know if that answers your questions.

I'll have a look at your pull requests in the next few days; they sound good!

Best regards, Miquel

On Fri, Dec 23, 2011 at 7:41 AM, Ka Yue Yeung < reply@reply.github.com

wrote:

Hi Mrtorrent

I was trying to figure out what does the following lines do in ApiLoader->load(), could you give me some hints?

$returnValue = require_once $bootstrap;

foreach (get_defined_vars() as $name => $value) { if ($name == 'bootstrap' or $name == 'returnValue') continue; $GLOBALS[$name] = $value; }

return $returnValue;

https://github.com/kayue/WordpressBundle/blob/master/Wordpress/ApiLoader.php#L79-84

Thank you so much!

Best Ka Yue


Reply to this email directly or view it on GitHub: https://github.com/kayue/WordpressBundle/issues/5

kayue commented 12 years ago

I see, thank you for your clear explanation.