I'm wondering about this weird thing:
public function getAllCustomers()
{
$customers = $this->redis->keys("customer:*");
foreach ($customers as $value) {
return new \Customer($this->redis->hget($value,"name"),$this->redis->hget($value,"id"),$this->redis->hget($value,"email"));
}
}
This method returns all customers from my database.
But if I try to loop through all of these customers:
foreach ($customerController->getAllCustomers() as $customer) {
var_dump($customer);
}
The getName() method is not found. var_dump returns:
NULL
NULL
NULL
Customer class:
class Customer {
var $name;
var $id;
var $email;
function __construct($name, $id,$email) {
$this->name = $name;
$this->id = $id;
$this->email = $email;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
public function __toString()
{
return "";
}
}
I'm pretty new to PHP and don't understand why I can't access the Customer object's field.
var_dumporprint_ron the$customerin your for-loop?return array(\Customer(...- are you also missing anewhere? The code you've posted should just cause a syntax error.