Basic PHP OOPS Query
- by appu
Ok. I am starting out OOPS in PHP. Created a couple of classes: customer(parent) and sales(child) class that inherits from parent class. Created another testcustomer.php in which a new sales object is created however the salesprint() function defined in the sales class does not echo out customer's name though it is set to be "Jane" in the class.customer.php(parent). My thinking is that when sales class extends customer class PHP automatically includes all the code from class.customer.php to sales.customer.php and therefore the constructor in parent class set $name to "Jane".
Here is the code: class.customer.php
<?php
class customer{
private $name;
private $cust_no;
public function __construct($customerid) {
$this->name = 'Jane';
$this->cust_no = $customerid;
}
}
?>
class.sales.php
<?php
require_once('class.customer.php');
class sales extends customer{
public function salesprint($customerid) {
echo "Hello $this->name this is a print of your purchased products";
}
}
?>
testcustomer.php
require_once('class.sales.php');
$objsales = new sales(17);
$objsales->salesprint(17);
?>
The Output I get
Hello this is a print of your purchased products.
What am i doing wrong ?
thanks
romesh