For some reason when I set the value(s) of a class variable it is not being saved in the session. It takes three consecutive attempts before it is saved. Here are some code fragments to illustrate this
//From index.php
if(session_is_registered("Worker") === false){
$WebApp = new MyApp();
$_SESSION['WebApp'] =& $WebApp;
}
else{
$WebApp =& $_SESSION['WebApp'];
}
$WebApp->Process($directive);
//file MyApp.class.php
class MyApp{
function MyApp(){
$this->modes = array("INDEX", "LOGIN", "LOGOUT");
print_r($this->modes);
}
function Process($d){
print_r($this->modes);
//bunch of processing
//including the creation of a user object
//named $Worker. $Worker is registered with the session
if(session_is_registered("Worker") === true){
$this->ResetModes($_SESSION['Worker']->GetModes());
print_r($this->modes);
}
}
function ResetModes($new_modes){
print_r($this->modes);
//This takes an array and appends it to $this->modes
//This function is working properly.
print_r($this->modes);
}
}
As you can see, I have several calls to
print_r($this->modes);
scattered through the code. As a page is accessed, a directive is sent to the app, telling what page it will visit next. Here is the result of page accesses:
Initial access, Webapp is not registered. It is created, listing contents of modes and registered. Process is called. Original modes list is printed. User is authenticated, original modes is listed again. After a successful call to ResetModes, the updated list is printed.
Second access, WebApp is already registered, each call to print_r($this->modes) prints exactly as in Initial access.
-
Third access and now print_r($this->modes) is printing the correct values.
Any ideas on why this strangeness occurs?