Can anyone figure out this php error message???

Posted on 2011-04-19
Medium Priority
Last Modified: 2012-08-13
Error messages are driving me crazy tonight.  This is my latest one:

Parse error: syntax error, unexpected T_FUNCTION, expecting T_VARIABLE in /hermes/web09c/b2950/moo.auroriellacom/includes/user.php on line 63

What does it mean by it was expecting a variable instead of a function??  (I did have the function as public but it didn't like that so I took that away)
require_once 'includes/database.php';

class User{ 

public $id;
public $username;
public $hash_password;
public $first_name;
public $last_name;

// Common Databaes Methods

protected static $table = "users";
private $object;

public static function find_all() {
	return self::find_by_sql("SELECT * FROM " . self::$table);
public static function find_by_id($id=0) {
	global $database;
	$result = self::find_by_sql("SELECT * FROM  " . self::$table . " WHERE id={$id} LIMIT 1");
	return !empty($result) ? array_shift($result) : false; //array_shift pulls the first item out
public static function find_by_sql($sql="") {
	global $database;
	$result = $database->query($sql);
	$object_array = array();
	while ($row = $database->fetch_array($result)) {
		$object_array[] = self::instantiate($row);
	return $object_array; // Must return an array!
private static function instantiate($record) {
	$class_name = get_called_class();
	$object = new $class_name; // Here is where it starts a new class for itself
	foreach($record as $attribute => $value) {
		if($object->has_attribute($attribute)) {
			$object->$attribute = $value;
	return $object;

// Unique to User

private function has_attribute($attribute) {
	// get_object_vars returns an associative array with all attributes
	// (including private ones) as the keys and their current value as the value
	$object_vars = get_object_vars($this);
	// We don't care about the value, we just want to know if the key exists
	// Will return true or false
	return array_key_exists($attribute, $object_vars);

function full_name() {
	if(isset($this->first_name) && isset($this->last_name)) {
		return $this->first_name . " " . $this->last_name;
	else {
		return "";
static function authenticate($username="", $hash_password="") {
	global $database;
	$username = $database->clean_strings($username);
	$hash_password = $database->clean_strings($hash_password);
	$sql = "SELECT * FROM users ";
	$sql .= "WHERE username = '$username' ";
	$sql .= "AND hash_password = '$hash_password' ";
	$sql .= "LIMIT 1";
	$result = self::find_by_sql($sql);
	return !empty($result) ? array_shift($result) : false; //array_shift pulls the first item out

} // End class User

Open in new window

Question by:FairyBusiness
  • 2
  • 2

Expert Comment

ID: 35430008
try to change 63. line to

public static function authenticate($username, $hash_password) {

Open in new window


Author Comment

ID: 35430017
I did and said this:

Parse error: syntax error, unexpected T_PUBLIC in /hermes/web09c/b2950/moo.auroriellacom/includes/user.php on line 63

Accepted Solution

4e4en earned 2000 total points
ID: 35430106
Oh and you have also forgot to close function "private function has_attribute($attribute)" it should have an "}" after line 53.
return array_key_exists($attribute, $object_vars);

Open in new window


Author Closing Comment

ID: 35430124
thanks, I totally missed that!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question