Catfish Posted April 1, 2008 Share Posted April 1, 2008 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 https://forums.phpfreaks.com/topic/98944-cannot-use-assign-op-error/ Share on other sites More sharing options...
Catfish Posted April 1, 2008 Author Share Posted April 1, 2008 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 https://forums.phpfreaks.com/topic/98944-cannot-use-assign-op-error/#findComment-506395 Share on other sites More sharing options...
cooldude832 Posted April 1, 2008 Share Posted April 1, 2008 you can't use connotation on what it thinks is an object so your initial creation of this item must make it not a string but an object. Link to comment https://forums.phpfreaks.com/topic/98944-cannot-use-assign-op-error/#findComment-506400 Share on other sites More sharing options...
Catfish Posted April 1, 2008 Author Share Posted April 1, 2008 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 https://forums.phpfreaks.com/topic/98944-cannot-use-assign-op-error/#findComment-506420 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.