how to execute this function ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
everydayrun
Forum Commoner
Posts: 51
Joined: Wed Jan 20, 2010 1:30 am

how to execute this function ?

Post by everydayrun »

Code: Select all

function drupal_bootstrap($phase) {
  static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL), $phase_index = 0;

  while ($phase >= $phase_index && isset($phases[$phase_index])) {
    $current_phase = $phases[$phase_index];
    unset($phases[$phase_index++]);
    _drupal_bootstrap($current_phase);
  }
}
now,if i use this drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); what result will be return. the thing that confused me is in the above function,there is no return. another is

Code: Select all

static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL), 
now the argument is DRUPAL_BOOTSTRAP_FULL, the line changes

Code: Select all

DRUPAL_BOOTSTRAP_FULL=array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL), 
this give the array to the variable DRUPAL_BOOTSTRAP_FULL. am i right? i feel it useless.thank you.
everydayrun
Forum Commoner
Posts: 51
Joined: Wed Jan 20, 2010 1:30 am

Re: how to execute this function ?

Post by everydayrun »

anyone helps?
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: how to execute this function ?

Post by cpetercarter »

I am not sure that I understand your difficulty, but I hope the following are helpful.

Functions do not need to return a value to the main programme.

This drupal_bootstrap() function performs some internal calculations and removes items from the array $phases . It then calls a separate function _drupal_bootstrap(), and passes a value ($current_phase) to it. I guess that _drupal_bootstrap() initialises Drupal and that the passed value $current_phase tells it what sort of initialising processes it should do.

The drupal_bootstrap() function contains two static variables. A static variable in a function "remembers" its value. So, if you have a function with an internal variable $v, which has an initial value of 0, and the function increments the value of $v to 1, then the next time the function is called, $v will have an initial value of 1.

In the drupal_bootstrap() function, the static variables in the function "remember" what is in the array $phases, and the value of $phase_index, from the last time the function was called.

I do not know what sort of value is in the constant DRUPAL_BOOTSTRAP_FULL so I do not know what will happen if you pass it as an argument to the drupal_bootstrap() function. But it will give the value of DRUPAL_BOOTSTRAP_FULL to the variable $phase, not the (array) variable $phases, so it will not have the result you suggest in your question.
everydayrun
Forum Commoner
Posts: 51
Joined: Wed Jan 20, 2010 1:30 am

Re: how to execute this function ?

Post by everydayrun »

OK,GOT IT.many thanks.
Post Reply