Php T_variable Error
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 each parse error syntax error unexpected '$name' (t_variable) other. Join them; it only takes a minute: Sign up Unexpected T_VARIABLE error up vote 7 down vote favorite 1 Okay, I know this is a common enough question, but all the solutions I've found thus far have
Parse Error: Syntax Error, Unexpected '$username' (t_variable)
involved a missing semi-colon or curly brace, both of which I know is not the case for me. I have a class that works FINE with this variable assignment: session.php: Great. But I want to have my database details in another file, so I did this: db_creds.php: 'localhost', ... ); ?> session.php Which then gave me this error: Parse error: syntax error, unexpected T_VARIABLE in ../session.php on line 74, where line 74 is my var $host assignment. I even tried doing this in session.php, just to be sure the problem wasn't in the include: session.php ... but that just throws the same error as above. Can anyone tell me what's happening here? I'm at my wits end! php include variables share|improve this question edited Jul 23 '12 at 21:48 user212218 asked Nov 7 '09 at 20:51 neezer 8,1692291186 add a comment| 2 Answers 2 active oldest votes up vote 9 down vote accepted Variables are not allowed here, properties must be initialized by constants in PHP: […] this initialization must be a constant value [Source: php.net manual] Use the constructor to intialize the value properly: class session { var $host; function __construct() { $this->host = $db_creds['host']; } } share|improve this answer answered Nov 7 '09 at 20:55 Konrad Rudolph 320k76656906 Ahh, got it. Still new to PHP classes and whatnot. Thanks! +1 –neezer Nov 7 '09 at 20:57 add a comment| up vote -1 down vote the first letter in a class name should be capital (class Session) did you write a constructor class p
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 syntax error, unexpected '$user' (t_variable) this site About Us Learn more about Stack Overflow the company Business
Expecting Variable (t_variable)
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
T Variable Statistics
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 http://stackoverflow.com/questions/1694378/unexpected-t-variable-error up PHP: unexpected T_VARIABLE error [closed] up vote -1 down vote favorite I made this tutorial for an anti leech script in PHP: http://tanksoftware.com/tutes/leechprotection.html Now by testing the php file online I become this error message: Parse error: syntax error, unexpected T_VARIABLE in /www/htdocs/myfolder/download.php on line 14 What is wrong on that line? This is the code: function generateSymLink($directory, $offset = 0) { http://stackoverflow.com/questions/5811962/php-unexpected-t-variable-error $day = ""; //todays day of the month, eg "14" $day = date("d", time() + (24*3600*$offset)); // A string which would look somthing like this "Monday, 14 Jan 2003MySecretKey/myfiles/example" $tohash = date("D, d M Y", time() + (24*3600*$offset))."My Secret Key".$directory // The first seven digits of the hash of the above string which would look somthing like // "a4h1b". $smallkey = substr(md5($tohash),0,5); return $day.$smallkey; } // extracts the file details $fullpath = "myfiles/example/file.tar.gz"; $seperated = explode("/", $row['Filename']); $actualfile = $seperated[sizeof($seperated)-1]; $path = substr($fullpath, 0,(strlen($fullpath)-strlen($actualfile))); // Gets the current working directory $wd = getcwd(); // Enters the download directory chdir("dl") or die("Unable to enter the download directory"); // Creates a new symlink if nessesary if (!file_exists(getSymLink($path))) symlink("../".$path, getSymLink($path)) or die("Unable to create download link"); // changes back to the directory of the script chdir ($wd); // Returns the current day of the month function getDnum($offset = 0) { return date("d", time() + (24*3600*$offset)); } // removes old symbolic links function cleanUpOldSymlinks () { // Only execute this code 1/10th of the time (to conserve CPU time). $randomNumber = rand(0,10); if ($randomNumber != 6) return; // enters the down