All pastes #506703 Raw Edit

Stuff

public text v1 · immutable
·published 2007-05-24 04:05 UTC
rendered paste body
<?php

class user {

function get_user($id) {
	// Assume DB Connection exists, etc.
	
	// Global Keyword lets us override the normal variable scope.
	global $db;
	
	$db->get_results("SELECT * FROM user where id = '$id'");
	
	// Parse results...
	// I'm not going to write this part.
	// It's self explanatory.
	
	// Assign vars to an array inside of the class.
	
	// Simple:
	$this->name = $user->name;
	$this->email = $user->email;
	
	// Complex... probably better.
	$this->vars = array(
				'name' => $user->name;
				'email' => $user->email;
			)
	}
}

// Call the class.
$user = new user;

// Get User
$user->get_user(1);

// What's the User Name? (Simple
echo $user->name;

// Complex
echo $user->vars['name'];

?>