php - Redeclare function in loop
I'm stumped as to how I would get this working. I'm using the twitteroauth.php library and I am grabbing the users token and token secret from a db query. Here is the code:
while($row = mysql_fetch_array($m))
{
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$consumerKey = "#####";
$consumerSecret = "#####";
$oauthToken = $row['oauth_token'];
$oauthTokenSecret = $row['oauth_token_secret'];
$userName = $row['username'];
$query = mysql_query("select url from retweets order by rand() limit 1");
$row = mysql_fetch_assoc($query);
$retweet = basename($row['url']);
$method = 'statuses/retweet/'.$retweet.'';
twitterOAuth($method, $connection->post($method), $connection->http_code, $userName);
}
If there are multiple results from mysql, it loops through and says:
Fatal error: Cannot redeclare random_from() (previously declared in /usr/share/nginx/www/twitteroauth/twitteroauth.php:199) in /usr/share/nginx/www/twitteroauth/twitteroauth.php on line 199
Since the$connection
variable relies on$oauthToken
and$oauthTokenSecret
from the mysql query, I can't move it outside of the loop, so how would I make it so I can use it in each loop without redeclaring?
Thank you in advance!
Update: This is twitterOAuth
function twitterOAuth($method, $response, $http_code, $userName, $parameters = '') {
if($http_code == 200){
echo "retweeted successfully @".$userName."<br />";
}else{
echo "an error has occurred while retweeting @".$userName."";
echo "<br />";
print_r($response);
}
}
Answer
Solution:
It needs to look like this...
You were declaring it before declaring the variables that you wanted to pass into it...