Parse Error Syntax Error Unexpected T_variable Expecting T_function In
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 about expecting function (t_function) php hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Syntax Error, Unexpected '$data' (t_variable), Expecting Function (t_function)
Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. syntax error unexpected this t_variable 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 out. In
Parse Error: Syntax Error, Unexpected T_variable In Php
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. 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:
in PHP Forum View Course » View Exercise 578 php class example points Submitted by Ruhi Mukherjee over 2 years ago Parse error: syntax error, unexpected T_VARIABLE, http://stackoverflow.com/questions/6486660/unexpected-t-variable-expecting-t-function expecting T_FUNCTION on line 26 My Code is getting submitted but is showing the error on line 26th Challenge Time! https://www.codecademy.com/en/forum_questions/5347bd307c82cae0dc0016f5 public $isAlive = true; public $numLegs = 4; public $name; public function __construct($name) { $this->name = $name; } public function meow() { return "Meow meow"; } $cat1 = new Cat("CodeCat"); //line 26 echo $cat1->meow(); } ?>