Php Syntax Error Unexpected T_var Expecting T_variable
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About unexpected var php Us Learn more about Stack Overflow the company Business Learn more about hiring
Php Unexpected T_variable
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the syntax error, unexpected t_variable Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up PHP Unexpected 'var' (T_VARIABLE) up parse error: syntax error, unexpected (t_variable) vote 0 down vote favorite For whatever reason, I have a small bit of PHP code that no matter where I put var $blah;, it always gives this error in the logs: PHP Parse error: syntax error, unexpected 'var' (T_VAR) in /path/to/file.php on line xx I have no idea why it wouldn't accept this. A class that is included (which creates the $proverbSite variable in another php section) uses plenty of 'var $blah', with no
Parse Error: Syntax Error, Unexpected '=' In
problems. I also realise this is probably just an embarassingly simple mistake. dbConnect(); $result = $proverbSite->dbQuery("randProverb"); if($result != null) { $row = $result->fetch_assoc(); echo $row['proverb']; echo "
"; } ?> php share|improve this question asked Jul 30 '13 at 0:44 ZephireNZ 4815 3 What's on line xx? –Barmar Jul 30 '13 at 0:46 3 And which is line xx ? –mario Jul 30 '13 at 0:46 1 Usually errors like this are due to unbalanced quotes, or a missing ; somewhere. –Barmar Jul 30 '13 at 0:47 1 Or it's due to using var $x=1; outside of a class declaration. –mario Jul 30 '13 at 0:47 1 possible duplicate of T_VAR Error with PHP –Barmar Jul 30 '13 at 0:50 | show 4 more comments 3 Answers 3 active oldest votes up vote 2 down vote accepted Keyword var is only used in classes (in PHP). In the plain scope variables are automatically declared as you mention them. Just erase it, and it should work. share|improve this answer answered Jul 30 '13 at 0:53 Lex Podgorny 1,322618 Yep, that was my problem. I didn't realise var was for clas
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about php variable hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up I'm getting a “syntax error, unexpected T_VARIABLE” error. I don't see what I'm doing wrong? up vote 3 down vote favorite I'm getting this error: "PHP Parse error: syntax error, http://stackoverflow.com/questions/17936577/php-unexpected-var-t-variable unexpected T_VARIABLE in /var/www/vhosts/... on line 66" Here's my code: function combine($charArr, $k) { $currentsize = sizeof($charArr); static $combs = array(); static $originalsize = $currentsize; ###### <-- LINE 66 ###### static $firstcall = true; if ($originalsize >= $k) { # Get the First Combination $comb = ''; if ($firstcall) { //if this is first call for ($i = $originalsize-$k; $i < $originalsize; $i++) { $comb .= $charArr[$i]; } $combs[] = $comb; //append the first combo to the output array http://stackoverflow.com/questions/5122729/im-getting-a-syntax-error-unexpected-t-variable-error-i-dont-see-what-im $firstcall = false; //we only want to do this during the first iteration } .... .... } Any idea what's wrong? php syntax-error parse-error share|improve this question asked Feb 25 '11 at 21:14 trusktr 11.4k2183127 why is $originalsize static if you overwrite it's value immediately on every function call? –Philipp Flenker Feb 25 '11 at 21:17 add a comment| 4 Answers 4 active oldest votes up vote 7 down vote accepted Quoting the manual (that page is about static properties, but the same applies for variables) : Like any other PHP static variable, static properties may only be initialized using a literal or constant; expressions are not allowed. So while you may initialize a static property to an integer or array (for instance), you may not initialize it to another variable, to a function return value, or to an object. You are using this : static $originalsize = $currentsize; Which is initializing with an expression -- and not a constant. And here's the manual's section that says quite the same about static variables : Static variables may be declared as seen in the examples above. Trying to assign values to these variables which are the result of expressions will cause a parse error. And, just in case, here's about expressions. In your case, to avoid that problem, I suppose you could modify your code, so it looks like this : $cur
Detected You currently have javascript disabled. Several functions may https://forums.phpfreaks.com/topic/286872-unexpected-t-var-expecting-variable-t-variable/ not work. Please re-enable javascript to access full functionality. unexpected (T_VAR), expecting variable (T_VARIABLE) Started by cybernet, Mar 11 2014 08:08 AM php class var variable Please log in to reply 2 replies to this topic #1 cybernet cybernet Advanced Member Members 88 posts Location/usr/sbin/mysqld Age:69 Posted 11 March syntax error 2014 - 08:08 AM so i found a pdo class to connect to mysql with pdo and looks easy to customize however i have an error that i can't figure it out class 'mysql:dbname=vax', 'username' => 'vax', 'password' => 'veryrandpasswd', ); public static getDbHandle(){ if(self::$_dbHandle == null){ self::$_dbHandle = new PDO( self::$_dbConfig['dsn'] , self::$_dbConfig['username'], self::$_dbConfig['password'] ); } return self::$_dbHandle; } } class StockMapper { protected $_dbh; public __construct($dbh = null) { if($dbh == null){ $this->_dbh = ApplicationResourcePool::getDbHandle(); } else { $this->_dbh = $dbh; } } public getStockById($stockId){ $sth=$this->_dbh->prepare("SELECT * from stock WHERE id = :stockId"); $sth->bindParam(":stockId", $stockId); $sth->execute(); $result = $sth->fetch(PDO::FETCH_ASSOC); return $result[0]; } } $stockMapper = new StockMapper(); $stockData = $stockMapper->getStockById('302'); ?> Parse error: syntax error, unexpected 'var' (T_VAR), expecting variable (T_VARIABLE) in /path/index.php on line 5 i really don't know what to do /usr/sbin/mysqld Back to top #2 jairathnem jairathnem Advanced Member Members 96 posts Posted 11 March 2014 - 08:58 AM static variable. doesn't make sense, does it? cybernet likes this Back to top #3 cybernet cybernet Advanced Member Members 88 posts Location/usr