Can anyone figure out this php error message???

Posted on 2011-04-19
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
    LVL 4

    Expert Comment

    try to change 63. line to

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

    Open in new window


    Author Comment

    I did and said this:

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

    Accepted Solution

    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

    thanks, I totally missed that!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now