Greywacke Posted June 15, 2010 Share Posted June 15, 2010 hi there,i receive the following error: Fatal error: Can't use function return value in write context in /home/dwtphovu/public_html/intellisource.co.za/test_8347379386/private/request_salespages.php on line 89Line 89 being:unset(current($GLOBALS[$sarray])); $sarray is set at the start of the function as follows, depending on the page level array that must be deleted from: function dropattribs($status) { switch ($status) { case 2: $sarray = "mailaddp"; break; case 4: $sarray = "mailaddl"; break; default: // 0 $sarray = "mailadds"; } foreach ($GLOBALS[$sarray] as $sdata) { // begin iterate suppliers array $arr = split(";;;",$sdata); // split supplier array $sid = $arr[6]; // get supplier id foreach ($GLOBALS["attribsarr"] as $key => $value) { // begin iterate form attributes // select current attribute key and bound values for supplier that are not supported $tsql = "SELECT 3_serviceattributes.text_AttributeDescription, 3_serviceattributes.text_AttributeValue FROM 9_supplierattributes JOIN (3_serviceattributes) ON (9_supplierattributes.bigint_AttributeID = 3_serviceattributes.bigint_AttributeID) WHERE 9_supplierattributes.bigint_ServiceID = ".$GLOBALS["service"]." AND 9_supplierattributes.bigint_RegionID = ".$GLOBALS["region"]." AND 9_supplierattributes.bigint_SupplierID = ".$sid.";"; $result = mysql_query_errors($tsql, $conn , __FILE__ , __LINE__ , false); if ($result) { // begin if mysql result while ($row = mysql_fetch_array($result)) { // begin while suppliers !attribs // begin if attrib key and value in db key and value if (stristr($key,strval($row["text_AttributeDescription"])) != false && stristr($value,strval($row["text_AttributeValue"])) != false) { // drop current $i from $mailadds/p/l array unset(current($GLOBALS[$sarray])); } // end if attrib key = db key } // end while suppliers !attributes mysql_free_result($result); } // end if mysql result } // end iterate form attributes } // end iterate suppliers array} somebody please help, these incongruencies need to be solved today - i have searched the net, but i can't seem to find a solution for this error when using unset to drop an array element. Link to comment Share on other sites More sharing options...
jeffman Posted June 15, 2010 Share Posted June 15, 2010 Would not current($GLOBALS[$sarray]) return the value of the current array element? This would mean that unset is trying to remove a value rather than a variable? That would explain the error. Unset is a kind of write operation. You cannot write to a value.As I say, I am guessing. It would depend on how deep your arrays are nested. You might try as an experiment using:var_dump(current($GLOBALS[$sarray]) )just to see what you are trying to unset.I also wonder about the use of current in this context. From the manual's discussion of foreach: foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it.My own small experiment with current in a foreach loop yielded very strange results. Link to comment Share on other sites More sharing options...
Greywacke Posted June 16, 2010 Author Share Posted June 16, 2010 Would not current($GLOBALS[$sarray]) return the value of the current array element? This would mean that unset is trying to remove a value rather than a variable? That would explain the error. Unset is a kind of write operation. You cannot write to a value.As I say, I am guessing. It would depend on how deep your arrays are nested. You might try as an experiment using:var_dump(current($GLOBALS[$sarray]) )just to see what you are trying to unset.I also wonder about the use of current in this context. From the manual's discussion of foreach:My own small experiment with current in a foreach loop yielded very strange results.well unfortunately that function cannot be used in that context (inside the unset function). it was generating an error - so i had to revert to using indices - i discovered the congruency. it was looping all records in the database, so if the consumer entered more than one attribute unsupported by the supplier - it deleted a supplier for each key and value matched against that supplier. i added a check, that only allows one supplier to be deleted no matter how many attributes it does not support. ^^ this issue has been resolved Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.