Php Array Syntax Error Unexpected 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 Us Learn more about Stack Overflow the company Business Learn more parse error syntax error unexpected t_variable in php about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users
Unexpected T Variable Php
Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping parse error: syntax error, unexpected '$username' (t_variable) 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
Parse Error Syntax Error Unexpected '$name' (t_variable)
error: syntax error, 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 php unexpected t_variable expecting t_function combo to the output array $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
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
Syntax Error, Unexpected '$user' (t_variable)
the company Business Learn more about hiring developers or posting ads with us Stack Overflow
Unexpected Variable
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 t variable statistics million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up What is unexpected T_VARIABLE in PHP? up vote 41 down vote favorite 2 I get this PHP error: Parse http://stackoverflow.com/questions/5122729/im-getting-a-syntax-error-unexpected-t-variable-error-i-dont-see-what-im error: syntax error, unexpected T_VARIABLE From this line: $list[$i][$docinfo['attrs']['@groupby']] = $docinfo['attrs']['@count']; Is there anything wrong with this line? php syntax-error share|improve this question edited Aug 7 '14 at 20:24 Eric Leschinski 47.1k23221191 asked Sep 23 '09 at 9:26 omg 34.5k103235315 X-Ref: PHP Parse/Syntax Errors; and How to solve them? - Unexpected T_VARIABLE for the other common causes and context-specific fixes. –mario Aug 18 '15 at 14:56 add a comment| 2 http://stackoverflow.com/questions/1464919/what-is-unexpected-t-variable-in-php Answers 2 active oldest votes up vote 89 down vote accepted There might be a semicolon or bracket missing a line before your pasted line. It seems fine to me, every string is allowed as array index. share|improve this answer edited Aug 7 '14 at 20:09 Eric Leschinski 47.1k23221191 answered Sep 23 '09 at 9:30 knittl 107k26167227 Oh you reminded me,it's a bracket missed.Why it's called T_VARIABLE? –omg Sep 23 '09 at 9:32 1 The error message tells you what's there (unexpected), not what's missing. And there's a variable, so it tells you exactly that. –OregonGhost Sep 23 '09 at 9:34 1 Because the unexpected $list is a variable. –Michael Krelin - hacker Sep 23 '09 at 9:34 2 because php was expecting a bracket and found a variable, that's why it tells you ‘unexpected variable’ –knittl Sep 23 '09 at 9:37 add a comment| up vote 8 down vote It could be some other line as well, PHP is not always that exact. Probably you are just missing a semicolon on previous line. How to reproduce this error, put this in a file called a.php: Run it: eric@dev ~ $ php a.php PHP Parse error: syntax e
error, unexpected T_VARIABLE If this is your first visit, be sure to check out the FAQ by clicking http://www.webdeveloper.com/forum/showthread.php?287981-Trying-to-initialise-an-array-but-getting-syntax-error-unexpected-T_VARIABLE the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you https://www.codecademy.com/en/forum_questions/53f618759c4e9d519c000599 want to visit from the selection below. Results 1 to 3 of 3 Thread: Trying to initialise an array but getting: syntax error, unexpected T_VARIABLE Tweet Thread syntax error Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 12-19-2013,07:29 PM #1 php-bgrader View Profile View Forum Posts Visit Homepage Registered User Join Date Dec 2013 Location Melbourne, Australia Posts 27 Trying to initialise an array but getting: syntax error, unexpected syntax error unexpected T_VARIABLE I'm trying to use array_push to create an array that looks like this: Code: array( "SaleTypeCat1" => array("Type1", Type2","Type3"), "SaleTypeCat2" => array("Type3") ) My code fails on this line: PHP Code: $this->valid_sale_types_categories[$row->sale_category]=array();
with: PHP Parse error: syntax error, unexpected T_VARIABLE This is my code - From what I have seen and read, I have followed the instructions to initialise my array however, the error suggests I'm not doing it correctly? PHP Code:
classSaleTypes{
private$valid_sale_types_categories;
functiongetSaleTypes($customer_id){
...
while($row=$result->fetch_object()){
//Needtoinitialisethearraybeforetryingtopushavaluetoit.
What is wrong with it? Thanks 0 votes permalink Main thing is you were missing a comma here join(", ", $the_array ); 438 points Submitted by smartalec about 2 years ago 1 Comment smartalec about 2 years ago Oh and you were missing the paragraph tags so that caused the output to show up inline. The CodeAcademy validator will get you for that