Basic class returns object reference instead of Array
Posted
by php-b-grader
on Stack Overflow
See other posts from Stack Overflow
or by php-b-grader
Published on 2010-05-27T01:43:18Z
Indexed on
2010/05/27
2:01 UTC
Read the original article
Hit count: 188
I have very basic class:
class Customer {
protected $id;
protected $customer;
public function __construct($customer_id) {
$this->id = $customer_id;
return $this->set_customer();
}
protected function set_customer() {
$query = mysql_query("SELECT * FROM customer WHERE id = '$this->id'");
$this->customer = mysql_fetch_row($query);
return $this->customer;
}
}
$customer = new Customer($order->customer->id);
print_r($customer);
This is not doing what I want it to but I understand why... $customer returns a reference to the Customer Object...
What I want is the MySQL row array from the mysql_fetch_row() - How do I return the array?
What am I missing?
© Stack Overflow or respective owner