NYCPHP Meetup

NYPHP.org

[nycphp-talk] Trouble Updating an array in a class

Randal Rust rrust at r2communications.com
Fri Nov 4 10:48:45 EST 2005


I am having issues with updating a property (which is an array) in a class.

In the class, I set the property:

var $modules=array();

There is a method in this class that fetches the modules from the database and
creates an array. This is called in my page, after the class is instantiated:

$moduleVars=$user->getModules($db);

At this point, if I loop through the array and print the results, I get...

NEWS =
ART =
CONT =
IMG =
PROJ =
EMP =
USER = 

...which is exactly correct. What I'm doing here is developing the permissions
portion of a CMS. So what I've done is set all my permissions to empty.

Now, when the page is submitted, I update the $moduleVars array with this:

	//pull modules and permissions from request string
	foreach($moduleVars as $moduleCode=>$moduleValue){
		if(isset($_REQUEST[$moduleCode])){
			$moduleValue=$_REQUEST[$moduleCode];
			//echo $moduleCode.' = '.$_REQUEST[$moduleCode].'<br />';
			}
		}

If I print the results out, I get the correct values that I selected for each
module:

NEWS = CRU
ART =
CONT = R
IMG =
PROJ =
EMP =
USER = R

Now, I have to pass this back to the class, and here is where my problem is.

Typically, I pull values from the query string like so...

$firstName=$_POST['firstName'];

...and then pass it to the class like this...

$user->firstName=$firstName;

This has always worked fine. But when I try to reset the array...

$user->modules=$moduleVars;

...and then print out what gets passed to the class, I get...

NEWS =
ART =
CONT =
IMG =
PROJ =
EMP =
USER = 

...as though what I am passing back is not the updated array, but the initial
version that was created when I called the getModules() method.

Can anyone explain why this is happening?


Randal Rust

-----------------------------
R.Squared Communications
Digital Design for Bricks-and-Mortar Business
www.r2communications.com




More information about the talk mailing list