Jump to content

"Cannot use assign-op" error


Catfish

Recommended Posts

Hi there,

 

I'm writing some PHP scripts and I have structured my code to have a file that holds common variables that most of my scripts need access to.

 

The variablesCommon.php file is loaded by my other PHP files using a 'require' call.

 

When I use one script (called "addExpense.php") I receive the following error:

 

Fatal error: Cannot use assign-op operators with overloaded objects nor string offsets in /var/www/hisb/data/variablesCommon.php on line 82

 

editing line 82 brings for the same error complaining about line 84. Line 82 and 84 of variablesCommon.php are:

 

$financeType['additional']     .= "<option value=\"".$key."\" #DEFAULTTYPE#>".$value."</option>";
$financeType['additional']             .= "</select>";

 

Changing the operators from .= to just . fixes this problem when I access addExpense.php but then if I use another script (called modifyRecord.php) the values of the $financeType['additional'] array index are not set correctly and the modifyRecord.php functionality is not correct.

 

So in summary:

If I use .= operator, modifyRecord.php works fine and no fatal errors but if I use .= for addExpense.php file it fails with the fatal error.

If I use . instead of .= then addExpense.php works fine but the functionality of modifyRecord.php is incorrect because the value of $financeType['additional'] is not correct.

 

Also note that variablesCommon.php is "required" by a number of other scripts I have and they don't complain about the two lines, it only happens with the addExpense.php page.

 

Please help as this error doesn't seem very logical to me and I can't determine why it is appearing.

Link to comment
Share on other sites

Ok, I'm not sure if I fixed this completely because I didn't know what I was doing wrong to start with, but I looked up some google on overloaded objects and I vaguely remember that stuff from when I did OOP during my small stint at uni a few years ago.

 

Anyhow, I figured that maybe the name of the array in variablesCommon.php ($financeType[]) might be conflicting or overloading with the variable passed by the addExpense.php ($_POST['financeType']) so I changed $financeType[] to $financeTypes[] and it seems to have fixed it.

 

 

The only thing is... I looked for $financeType[] in the other files that would use it and couldn't find it. Heh heh heh... I know what I use the array for but i can't remember where exactly I use it. Anyway, looks like everything is working for now.

Link to comment
Share on other sites

I simply make the associative array using:

 

$financeTypes['indexName'] = "Text to Output";

 

each index I make is done in that fashion (there are only 3 indices), but only the 'additional' index's value is appended to and was the one making the fatal error.

 

It seems to be working now since renaming the array.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.