Hello fellow PHP geeks, I'm sort of in a weird situation... One of which I've never come into before (It's maybe due to my break from PHP to .Net). Using the framework CodeIgniter.
Well here's the situation... I've got a User class which acts as the user object containing username/password/email etc... (shown below):
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include_once(APPPATH . INTERFACE_PATH . 'IUser' . EXT);
include_once(APPPATH . CLASS_PATH . 'Encryption' . EXT);
final class User extends Encryption implements IUser
{
private $_username;
private $_password;
private $_email;
public function SetUserData(StdClass $data)
{
$this->_username = $data->Username;
$this->_password = self::EncryptPassword($data->Password);
$this->_email = $data->Email;
}
public function Username()
{
return (string)$this->_username;
}
public function Password()
{
return (string)$this->_password;
}
public function Email()
{
return (string)$this->_email;
}
}
?>
Now nothing exciting so far... However once this has the values in etc... one should think using this class elsewhere will be simple... DOHHH well it isn't
Here's where it's being used:
<?php
#some class/methods up here...
public function AddNewUser(User $user) #here is where it's passed in...
{
print '<pre>';
print_r($user); # my output of this is shown in email.
print '</pre>';
return;
$user->Username = $this->db->escape($user->Username);
$user->Password = $this->db->escape($user->Password);
$user->Email = $this->db->escape($user->Email);
$sql = 'CALL sp_RegisterUser(' . $user->Username . ', ' .
$user->Password . ', ' . $user->Email . ', '
. (int)((isset($user->RefId) && is_numeric($user->RefId))
? $user->RefId : 0) . ', @usersId);';
$query = $this->db->query($sql);
if($query)
{
$sql = "SELECT @usersId;";
$query = $this->db->query($sql);
if($query->num_rows())
{
$sqlData = $query->result();
$query->free_result();
foreach($sqlData[0] as $k => $v)
{
$array[$k] = $v;
}
return (int)$array['@usersId'];
}
}
}
}
Now the print_r outputs the following:
User Object
(
[_username:private] => joebloggs
[_password:private] => m/SzYRxTF29cZJqk/B/2sg==
[_email:private] => [email protected]
)
How come the methods are now called the variables being returned but with their value?
Confusing times...
Any help is much appreciated.
Thanks, Shaun
PS, I've also included the class/interface in the other library so there's no excuse of the object not knowing how it should render.