setting vars from within the class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
theman68
Forum Newbie
Posts: 1
Joined: Fri Sep 28, 2012 10:36 pm

setting vars from within the class

Post by theman68 »

hi fellow coders
im a little new to classes but i have this code snippet which i wrote and i can set all the vars from with in the class but then the vars from outside of the class are all set to defaults. can anyone help me with this problem please.

<?php


// If it's going to need the database, then it's
// probably smart to require it before we start.

require_once PHP.DS."private/initialize.php";


class User extends master{

public $id;
public $email;
private $pass;
public $user_name;
private $userLev = 'guest';
public $f_name;
public $l_name;
public $user_object = array();


public function get_level(){
echo $this->userLev;
}

public function full_name() {
$user = new User();
if(isset($User->f_name) && isset($User->Lname)) {
return $User->f_name . " " . $User->Lname;
} else {
return "Guest";
}
}

private function set_user_vals($record) {
// Could check that $record exists and is an array
$object = new self;

// More dynamic, short-form approach:

foreach($record as $attribute=>$value){

// none of these are currently setting outside of this function for reference later

if($object->has_attribute($attribute)) {
$this->$attribute = $value;

array_push($this->user_object,$value);

}
}

return $object;
}


public function call_set_vals($record){
return $this->set_user_vals($record);
}

public static function authenticate($username="", $password="") {

global $database;
$username = $database->escape_value($username);
$password = $database->escape_value($password);

$sql = "SELECT * FROM users ";
$sql .= "WHERE email = '{$username}' ";
$sql .= "AND pass = '{$password}' ";
$sql .= "LIMIT 1";

$result_array = self::find_by_sql($sql);

return !empty($result_array) ? array_shift($result_array) : false;

}

public function call_level_check() {
$user = new UPR;
$res = $user->level_check($this->userLev,$this->email);
$this->userLev = $user->level;
return $this->userLev;
}

}



$Ur = new User();

echo $Ur->get_level();
echo "<br/>";
echo $Ur->email;
Post Reply