10 Replies - 2269 Views - Last Post: 29 August 2011 - 01:52 PM Rate Topic: -----

#1 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 927
  • View blog
  • Posts: 3,208
  • Joined: 19-January 10

Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 11:57 AM

God, I'm in one of those projects where it's all fine and dandy on my two different servers, but as soon as the client test it, it doesn't work and I look like a complete retard while hindering any future opportunities with this client.

Everything works _FINE_ on my end. But as soon as he tried it, he gets this error:

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in (file) on line 4

The file it's having the problem in is a class. Line 4:

Quote

public $username;


Just a note, he's running 4.X and I'm running 5.3, could that affect it? I wrote it for 4.3, but checked it using this (which I have been told isn't that reliable).

Is This A Good Question/Topic? 0
  • +

Replies To: Parse error: syntax error, unexpected T_STRING

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4356
  • View blog
  • Posts: 12,175
  • Joined: 18-April 07

Re: Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 12:01 PM

Show us the whole class creative... don't get cheap on us now! That error is usually involved with the code around the line it is bitching about, not the exact line.

;)
Was This Post Helpful? 1
  • +
  • -

#3 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 927
  • View blog
  • Posts: 3,208
  • Joined: 19-January 10

Re: Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 12:05 PM

<?php
class admin
{
	public $username;

	public function __construct(){
		session_start();
		if(empty($_SESSION['logged_in'])){
			header('location: login.php');
			die();
		}
		$file = $this->get_contents("adminData.txt");
		$file = explode(", ", $file);
		$this->username = $file[0];
	}
	
	public function links(){
		$links = array("Manage forms" => "manage.php", "New form" => "newForm.php", "Manage bans" => "bans.php", "Account" => "account.php");
		foreach($links as $name => $link){
			echo '<b><a href="' . $link . '">' . $name . '</a></b><br />';
		}
	}
	
	public function login($username, $password){
		$file = $this->get_contents("adminData.txt");
		$file = explode(", ", $file);
		if($username == $file[0] && sha1($password) == $file[1]){
			$_SESSION['logged_in'] = true;
			return true;
		} else {
			$_SESSION['logged_in'] = false;
			return false;
		}
	}
	
	public function logout(){
		$_SESSION['isadmin'] = false;
		return true;
	}
	
	public function get_contents($file){
		$fh = fopen($file, 'r');
		$data = @fread($fh, filesize($file));
		fclose($fh);
		return $data;
	}
	
	public function put_contents($file, $contents){
		$fh = fopen($file, 'w');
		$result = fwrite($fh, $contents);
		fclose($fh);
		return $result;
	}
	
	public function getForms(){
		$forms = array();
		if($handle = opendir("../backend/data/")){
			while(false !== ($file = readdir($handle))){
				if($file != "." && $file != ".." && $file != "settings.ini" && $file != "infoBlocks"){
					$forms[] = $file;
				}
			}
		}
		closedir($handle);
		return $forms;
	}
}
?>

Was This Post Helpful? 0
  • +
  • -

#4 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 927
  • View blog
  • Posts: 3,208
  • Joined: 19-January 10

Re: Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 12:17 PM

Bleh, I think I found it. In PHP 4, variables have to be declared with var.

line 4 should be: public var $username;


Tell me if I'm wrong, cause it would pretty much be horrible if I gave him another version that didn't work.

http://www.php.net/m...yword.class.php
Was This Post Helpful? 0
  • +
  • -

#5 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4356
  • View blog
  • Posts: 12,175
  • Joined: 18-April 07

Re: Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 12:24 PM

Is he using PHP 4?

If he is using PHP 4 then remember you can't use __construct... that was introduced in PHP 5. Constructors in 4 are functions with the same name as the class.

Edit: And yes, you use var in PHP 4.

:)

This post has been edited by Martyr2: 29 August 2011 - 12:28 PM

Was This Post Helpful? 0
  • +
  • -

#6 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 927
  • View blog
  • Posts: 3,208
  • Joined: 19-January 10

Re: Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 12:29 PM

So it would be "public admin" or "public function admin"?
Was This Post Helpful? 0
  • +
  • -

#7 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4356
  • View blog
  • Posts: 12,175
  • Joined: 18-April 07

Re: Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 12:33 PM

Just "function admin()". Visibility keywords such as public/private are another PHP 5 invention.
Was This Post Helpful? 0
  • +
  • -

#8 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 927
  • View blog
  • Posts: 3,208
  • Joined: 19-January 10

Re: Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 12:45 PM

View PostMartyr2, on 29 August 2011 - 08:33 PM, said:

Just "function admin()". Visibility keywords such as public/private are another PHP 5 invention.


So I should ditch "public" altogether on everything?
Was This Post Helpful? 0
  • +
  • -

#9 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4356
  • View blog
  • Posts: 12,175
  • Joined: 18-April 07

Re: Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 12:50 PM

For PHP 4 you should be using var $username; and drop "public" off of all the functions. Then you should be looking pretty good.

But just keep in mind that many functions these days may not have been available in PHP 4. So be sure to check each before using it.

:)

This post has been edited by Martyr2: 29 August 2011 - 12:51 PM

Was This Post Helpful? 0
  • +
  • -

#10 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 01:35 PM

Yuck. Just out of curiosity creativecoding why is your client running such an old version of PHP?
Was This Post Helpful? 0
  • +
  • -

#11 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 927
  • View blog
  • Posts: 3,208
  • Joined: 19-January 10

Re: Parse error: syntax error, unexpected T_STRING

Posted 29 August 2011 - 01:52 PM

View PostJstall, on 29 August 2011 - 09:35 PM, said:

Yuck. Just out of curiosity creativecoding why is your client running such an old version of PHP?


He said that his admin told him that they run PHP 4, I asked if he was able to upgrade and he said he was sure that he could not.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1