Как в статическом приватном поле products хранить все созданные продукты(Processors и Ram).Т.е что бы это поле было регистром продуктов
<?php
namespace lesson2;
header('Content-Type: text/html; charset=utf-8');
class User{
private $name;
private $balance;
function __construct($name,$balance){
$this->name = $name;
$this->balance = $balance;
}
public function getName(){
return $this->name;
}
public function getBalance(){
return $this->balance;
}
public function __toString(){
return "У пользователя ".$this->getName()." сейчас на счету ".$this->getBalance()."<br/>";
}
public function giveMoney($user, $amount){
if($amount > $this->balance){
echo 'Недостаточно средств!'."<br/>";
}
else{
$this->balance = $this->balance - $amount;
$user->balance = $user->balance + $amount;
echo "Пользователь ".$this->getName()." перечислил ".$amount." пользователю ".$this->getBalance()."<br/>";
}
}
}
abstract class Product{
private $name;
private $price;
private $owner;
static private $products;
public function setOwner(User $user){
$this->owner = $user;
}
function __construct($name, $price, $owner){
$this->name = $name;
$this->price = $price;
$this->owner = $owner;
}
}
class Processor extends Product{
private $frequency;
}
class Ram extends Product{
private $type;
private $memory;
}