I’m fighting with code:
$worker = new Worker(); // :|
$worker->addWorker;
//testing
//testing
// $_SESSION['worker']->addWorker();
echo $_POST['name'];
echo $worker->name;
which should two last lines should show the same value. The assign method in class looks like that:
public function addWorker()
{
$this->name = $_POST['name'];
$this->surname = $_POST['surname'];
$this->dob = $_POST['dob'];
$this->skills = $_POST['skills'];
$this->postcode = $_POST['postcode'];
$this->street = $_POST['street'];
$this->email = $_POST['email'];
$this->tel = $_POST['tel'];
$this->erefnumber = $_POST['erefnumber'];
}
I’v got declared class Worker properties. The problem is that I don’t have any error, $worker->name just gives anything. echo $_POST[‘name’] works fine.
Your code is almost fine, but you do:
while it should be:
Also, to improve readability of your code, I’d consider changing
addWorker()to require array argument:and pass
$_POSTwhile invoking: