Parse Error Syntax Error Unexpected T_include Expecting 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 parse error syntax error unexpected expecting function t_function Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
Unexpected End Of File, Expecting Function (t_function)
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, syntax error, unexpected '$data' (t_variable), expecting function (t_function) just like you, helping 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 syntax error unexpected this t_variable I overlooked, but I can't figure it 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 Function T_function
{ $connection = sqlite_open("[path]/data/users.sqlite", 0666); public function lookupUser($username) { // 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 compil
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 syntax error, unexpected '->' (t_object_operator) Learn more about Stack Overflow the company Business Learn more about hiring developers class constructor php or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow
Parse Error Syntax Error Unexpected T_variable
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 syntax error, unexpected T_RETURN, expecting T_FUNCTION oop php http://stackoverflow.com/questions/6486660/unexpected-t-variable-expecting-t-function [closed] up vote 2 down vote favorite Im receiving an error as stated above. Its referring to my return statement. Any one got any clues on this?! Thankful for all help! Regards! public function getPosts() { $result = $this->db->query("SELECT * FROM posts"); $posts = array(); while($posts = $result->fetch_assoc()) { array_push($posts, new Post($post['id'], $post['created'], $post['author'], $post['title'], $post['body'])); } } return $posts; syntax-error php share|improve this question edited Feb http://stackoverflow.com/questions/3667556/syntax-error-unexpected-t-return-expecting-t-function-oop-php 23 '13 at 11:54 tereško 42.6k1567124 asked Sep 8 '10 at 12:10 Tim 1662420 closed as too localized by tereško, cryptic ツ, NikiC, PeeHaa, Dejan Marjanovic Feb 24 '13 at 2:57 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question. add a comment| 2 Answers 2 active oldest votes up vote 9 down vote Your return statement should come before the last closing brace. while($posts = $result->fetch_assoc()) { array_push($posts, new Post($post['id'], $post['created'], $post['author'], $post['title'], $post['body'])); } return $posts; } share|improve this answer answered Sep 8 '10 at 12:11 BoltClock♦ 385k959371048 @Pekka: fine! :P –BoltClock♦ Sep 8 '10 at 12:16 thanks for the quick answers. I found the answer just after I posted the question :) a bit to quick on my finger I reckon. Thanks! –Tim Sep 8 '10 at 12:21 1 @Pekka the pot
Forum View Course 176 points Submitted by James Barclay about http://forum.joomla.org/viewtopic.php?t=537399 3 years ago Confusing error with PHP objects - Unexpected T_VARIABLE, expecting T_FUNCTION Whenever I syntax error 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 syntax error unexpected 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