user.class.php
<?php
class User
{
private $data;
public function __construct(Array $properties=array())
{
$this->data = $properties;
}
public function __set($property, $value)
{
return $this->data[$property] = $value;
}
public function __get($property)
{
return array_key_exists($property, $this->data) ? $this->data[$property] : null;
}
function register()
{
var_dump($this->data);
}
}
?>
process_register.php
<?php include 'user.class.php'; $user = new User(array($_POST['username'], $_POST['password'], $_POST['email'])); //testing setter $user->data = $_POST['username']; $user->data = $_POST['password']; $user->data = $_POST['email']; $user->register(); ?>
index.php Just in case you wanted to know
<html>
<body>
<form name="register" action="register_process.php" method="post">
Username: <input type="text" name="username" />
Password: <input type="password" name="password" />
E-mail: <input type="text" name="email" />
<input type="submit" value="Register" />
</form>
</body>
</html>
<?php
//insert code here
?>
The problem is that while creating the object I can only add one of the values when trying to set... perhaps I'm doing it wrong but how can I set multiple values to the $data array? As of right now I only have 4 values: username, password and email created by the constructor, than email again added by the setter.
I just need a little direction. Thank you for your time.
*EDIT* I meant to say "Setting an array properly in class?" oops...
This post has been edited by kiasta: 12 October 2012 - 08:51 PM

New Topic/Question
Reply



MultiQuote




|