Error Unexpected T_variable Expecting T_old_function Or T_function
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 unexpected (t_variable), expecting function (t_function) about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users expecting function (t_function) php Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping syntax error, unexpected '$data' (t_variable), expecting function (t_function) each other. Join them; it only takes a minute: Sign up unexpected T_VARIABLE, expecting T_FUNCTION up vote 11 down vote favorite 3 I am expecting this to be a basic syntax error I overlooked, but I can't figure it expecting t_function out. In a PHP script, I keep getting the following error. Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in [path]/scripts/users/database_connection.php on line 4 This occurs when my script to connect to the database is called with an include_once(). I stripped my script down to the most basic code (leaving in what is required by other code), and it still is calling this error.
Syntax Error Unexpected This T_variable
rest of my code... } } $udb = new UserDatabaseConnection; ?> I have struggled with this for a while, and just wondered if anyone else could spot somewhere I went wrong. php sqlite syntax-error share|improve this question asked Jun 26 '11 at 20:50 Ryan Leonard 5241525 add a comment| 4 Answers 4 active oldest votes up vote 14 down vote accepted You can not put $connection = sqlite_open("[path]/data/users.sqlite", 0666); outside the class construction. You have to put that line inside a function or the constructor but you can not place it where you have now. share|improve this answer answered Jun 26 '11 at 20:53 Sabeen Malik 9,19821940 Thank you, first time I tried to use OOP. –Ryan Leonard Jun 26 '11 at 20:57 @Rhino , its aright. @Lekensteyn has done a wonderful job and shows you how you should ideally do it. –Sabeen Malik Jun 26 '11 at 20:58 add a comment| up vote 13 down vote You cannot use function calls in a class construction, you should initialize that value in the constructor function. From the PHP Manual on class properties: This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated. A working code sample:
Forum View Course 176 points Submitted by James Barclay about class constructor php 3 years ago Confusing error with PHP objects - Unexpected T_VARIABLE, expecting T_FUNCTION Whenever I http://stackoverflow.com/questions/6486660/unexpected-t-variable-expecting-t-function create a new instance of an object I receive this error: Parse error: syntax error, unexpected TVARIABLE, expecting TFUNCTION on line ...(in the example to come, line 10) The code passes https://www.codecademy.com/en/forum_questions/5211e84af10c607d6b000ff0 each task, however I just wanted to know whether this is actually a legitimate error in how I'm writing the code or whether it is a error not related to me. Below is the simplest code I have done that still produces the error.
` 1 vote permalink You're supposed to create the instance outside of the class: class Person{ } $me = new Person(); 322 points Submitted by DM about 3 years ago
years ago Unanswered New Active Featured Please post any ChronoForms bugs you found here Parse error: syntax error, unexpected '$', expecting T_VARIA Locked 9 7669 Showing 1 to 10 https://www.chronoengine.com/forums/posts/f3/t12599/parse-error-syntax-error-unexpected-expecting-t-varia.html of 10 entries. Parse error: syntax error, unexpected '$', expecting T_VARIA Sun Feb https://www.drupal.org/node/119109 15, 2009, 4:23 am Hi guysI'm trying to get my first form to work and I keep getting this error. I've been all over the forums here and else where and while it appears to be a simple formatting error I can't for the life of me find the thing.The full syntax error error message is this;Parse error: syntax error, unexpected '$', expecting T_VARIABLE in /home8/mycgpimp/public_html/components/com_chronocontact/chronocontact.php(41) : eval()'d code on line 72Lines 41 and 72 are as follows;39 $paramsvalues = $registry_cf->toObject( );40 if($paramsvalues->dbconnection == "Yes"){41 eval ("?>" .$rows[0]->dbclasses);42 }67 function showform($posted)68 {69 global $mainframe;70 $database =& JFactory::getDBO();71 72 //clear any stored sessions73 $session =& JFactory::getSession();74 if(!$posted){75 $session->set("chrono_verification_msg", '', md5('chrono'));76 }I've also checked all my field names expecting function (t_function) to make sure that there aren't any numbers at the start etc. I do have a few with '_' inbetween elements and they're all in uppercase if that's an issue. As I'm not familiar with PHP I'm in the dark here.any and all help appreciated.Kind regardsTim
tymotzues 18 0 Sun Feb 15, 2009, 4:02 am PM Re: Parse error: syntax error, unexpected '$', expecting T_VARIA Sun Feb 15, 2009, 8:17 am Hi Tim,It's line 72 of the code which is being "eval'd" on line 41 - in this case 41 eval ("?>" .$rows[0]->dbclasses);.Most likely you have a '-' or another non-standard character in one of your field names??Bob ChronoForms technical supportIf you'd like to buy me a coffee or two, thank you very much GreyHead Moderator 45243 56323 Tue May 29, 2007, 6:15 pm PM Online Re: Parse error: syntax error, unexpected '$', expecting T_VARIA Wed Feb 18, 2009, 2:47 am Thanks BobI'll look into itKind regardsTim tymotzues 18 0 Sun Feb 15, 2009, 4:02 am PM Re: Parse error: syntax error, unexpected '$', expecting T_VARIA Mon Feb 22, 2010, 2:46 pm Hi all,I had exact the same problem,that make connections all over the world. Join today Download & Extend Drupal Core Distributions Modules Themes TimesheetIssues Parse error: syntax error, unexpected T_VARIABLE ActiveProject:TimesheetVersion:4.7.x-1.x-devComponent:CodePriority:CriticalCategory:Bug reportAssigned:UnassignedReporter:siluriusCreated:February 14, 2007 - 18:33Updated:February 14, 2007 - 18:35 Log in or register to update this issue Configuration: Drupal 4.7.6 Apache 2.0.55 PHP 4.4.2-1.1 MySQL 5.0.24a-Debian_9-log Charset utf8 Upon uploading the Timesheet module to /modules/timesheet, I get the following error: Parse error: syntax error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /var/www/mypath/modules/timesheet/timesheet_legacy.inc on line 32 Lines 30-40 from timesheet_legacy.inc: class timesheet { $_uid; $_tid; $_lid; $_default_hours; $_timesheet; $_submit_date; $_approve_date; $_end_date; $_days_left; This occurs independently of whether or not the tables have been created or fpdf uploaded into the modules/timesheet folder in advance. Comments Comment #1 silurius CreditAttribution: silurius commented February 14, 2007 at 6:35pm I note that the readme mentioned no MySQL 4+ support, but I thought I had read elsewhere that this is now supported. Log in or register to post comments Add child issue, clone issue News itemsDrupal news Planet Drupal Association news Social media directory Security announcements Jobs Our communityCommunity Getting involved Services, Training & Hosting Groups & Meetups DrupalCon Code of conduct DocumentationDocumentation Drupal 8 docs Drupal 7 docs Developer docs api.drupal.org Drupal code baseDownload & Extend Drupal core Modules Themes Distributions Governance of communityAbout Web accessibility The Drupal Association About Drupal.org Terms of service Privacy policy Drupal is a registered trademark of Dries Buytaert.