myrddinwylt Posted July 10, 2010 Share Posted July 10, 2010 Here is a bizzare error..... if(trim($cost . "") == "") { $cost = "0"; } Sometimes returns the following error in the browser : WTF!! Fatal error: Can't use function return value in write context in C:\server\websites\127.0.0.1\htdocs-ssl\cdrdownloader\mysql.class.php on line 95 Link to comment https://forums.phpfreaks.com/topic/207361-cant-use-function-return-value-in-write-context/ Share on other sites More sharing options...
ChemicalBliss Posted July 10, 2010 Share Posted July 10, 2010 Sometimes? Do some tests and tell us what values of $cost cause this behaviour. -cb- Link to comment https://forums.phpfreaks.com/topic/207361-cant-use-function-return-value-in-write-context/#findComment-1084168 Share on other sites More sharing options...
ChemicalBliss Posted July 10, 2010 Share Posted July 10, 2010 FYI, this should only happen if you accidentally wrote this instead: if(trim($cost . "") = "") { $cost = "0"; } (note the single = operator (assignment), should be ==) -cb- Link to comment https://forums.phpfreaks.com/topic/207361-cant-use-function-return-value-in-write-context/#findComment-1084169 Share on other sites More sharing options...
harristweed Posted July 10, 2010 Share Posted July 10, 2010 why not if(empty($cost))$cost="0" ? Link to comment https://forums.phpfreaks.com/topic/207361-cant-use-function-return-value-in-write-context/#findComment-1084181 Share on other sites More sharing options...
myrddinwylt Posted July 10, 2010 Author Share Posted July 10, 2010 @ChemicalBliss: Yes, that is a typo in my post here only. The actual code contains "==" for the comparison. @harristweed: I do it this way as it is getting a value set from the database, which could be multiple blank spaces, or a null, but ideally I wish it to always be numeric. The code where the variable is being set is as follows: function dumpsql($daydownloaded) { $con = mysql_connect($this->server,$this->username,$this->password) or die(mysql_error()); $sql = ''; set_time_limit(3600); if ($con !== false){ mysql_select_db($this->database); $query="SELECT * FROM `" . $this->database_temp . "`.`" . substr($daydownloaded,0,-3) . "` ORDER BY `Started` ASC;"; $result=mysql_query($query,$con) or die(mysql_error()); $num=mysql_numrows($result); $i=0; if ($num > $i) { $sql[] = "CREATE TABLE IF NOT EXISTS `" . $this->database . "`.`" . substr($daydownloaded,0,-3) . "` (`uniqueid` int(11) NOT NULL AUTO_INCREMENT, `Caller` varchar(255) DEFAULT NULL, `Started` datetime DEFAULT NULL, `Dialed` varchar(255) DEFAULT NULL, `DurationSec` int(11) DEFAULT NULL, `DurationMin` int(11) DEFAULT NULL, `Cost` double DEFAULT NULL, `Location` varchar(60) DEFAULT NULL, `Switch` varchar(15) DEFAULT NULL, PRIMARY KEY (`uniqueid`)) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;"; $sql[] = "DELETE FROM `" . $this->database . "`.`" . substr($daydownloaded,0,-3) . "` WHERE `Started` LIKE '" . $daydownloaded . "%';"; } while ($i < $num) { $caller = mysql_result($result,$i,"Caller"); $started = mysql_result($result,$i,"Started"); $dialed = mysql_result($result,$i,"Dialed"); $durationsec = mysql_result($result,$i,"DurationSec"); $durationmin = mysql_result($result,$i,"DurationMin"); $cost = mysql_result($result,$i,"Cost"); if(trim($cost . "") == "") { $cost = "0"; } $location = mysql_result($result,$i,"Location"); $switch = mysql_result($result,$i,"Switch"); $sql[] = "INSERT INTO `" . $this->database . "`.`" . substr($daydownloaded,0,-3) . "` VALUES(null, '" . $caller . "', '" . $started . "', '" . $dialed . "', " . $durationsec . ", " . $durationmin . ", " . $cost . ",'" . $location . "','" . $switch . "');"; $i++; } mysql_close($con); } unset($con, $caller, $started, $dialed, $durationsec, $durationmin, $cost, $location, $switch); return $sql; } This error occurs only when the condition is met. Link to comment https://forums.phpfreaks.com/topic/207361-cant-use-function-return-value-in-write-context/#findComment-1084200 Share on other sites More sharing options...
ChemicalBliss Posted July 10, 2010 Share Posted July 10, 2010 Hmm, i cannot reproduce this error without using a single = operator. So i cannot help you in that respect, maybe do a quick search on php bugs see if someone has posted already , if not then psot with as much info as possible so they can try to reproduce it. for now though, i would do this part like this: if(!is_numeric($cost)) { $cost = "0"; } -cb- Link to comment https://forums.phpfreaks.com/topic/207361-cant-use-function-return-value-in-write-context/#findComment-1084227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.