Question: I have a doubt about the design of a system to manage items of a store using OOP.
I created the abstract class Product that will have the attributes $name and $price. Later I created the class Smartphone that extends Product. Smartphone has the attributes $brand and $os. Later I created the class Computer that extends Product and has attributes $cpuFrequency and $ram. Now, if I want to create an object corresponding to the Nexus 5, for example, what i have to do?
Consider, for example, that this object will have

```
$name = "Nexus 5"
$price = "250"
$brand = "LG"
$os="Android"
$cpuFrequency "2.0"
$ram = "2".

```

Here an example of classes.

```
abstract class Product {
    private $name;
    private $price; 
    //more methods
}

class Smartphone extends Product{
    private $brand;
    private $os;    
}

class Computer extends Product {
    private $cpuFrequency;
    private $ram;   
}

```

Also considered that there may be Computer without $os and Smartphone without $ram. just one example: D

P.S. I know that smartphone is a computer. I did a bad example. Please think at Telephone and Computer. Telephone has $number and $operator. Now i want to create a Smartphone that is at the same time Telephone and Computer.

Thanks for all and sorry again for my english

Answer: 
Normally, you should write constructors to your classes in some way that "child" class initialize the super class, to keep everything consistent.

```
abstract class Product {
    private $name;
    private $price; 
    //more methods

    public __construct($name, $price){
        $this->name = $name;
        $this->price =$price;
    }
}

class Smartphone extends Product{
    private $brand;
    private $os;
    // default value to $os: like that, we can create a Smartphone whitout an os
    public __construct($name, $price, $brand, $os = null){
        parent::__construct($name, $price);
        $this->brand = $brand;
        $this->os =$os;
    }
}

class Computer extends Product {
    private $cpuFrequency;
    private $ram;
    // default value to $ram: with this, we can create a Computer whiout ram
    public __construct($name, $price, $frequency, $ram = null){
        parent::__construct($name, $price);
        $this->frequency = $frequency;
        $this->ram =$ram;
    }

}

```

Then, to create a *Computer*, you can do, for 

```
$computer = new Computer('notBuiltToWindows', 560 , 2.0, 4);

```

or, to create the Nexus in your example:

```
$nexus = new Smartphone($name, $price, $frequency, $ram);

```

and, to create a smartphone whitout a ram

```
$nexus = new Smartphone($name, $price, $frequency);

```
The way we do it at work is a combination of most of the above answers:

1) You have a product class / object - this contains the generic things that any product will have - a name, a description, some pictures, etc

2) You have a sub-class which contain the product attributes (a product attribute class) - e.g. size, weight (not all products are physical, so not all have sizes or weights), price, number\_of\_ram\_slots, cupFrequency.

We allow the attributes to be user-defined by using an ORM that maps the attributes to the database. This gets the best of both worlds due to php not being able to do multiple inheritance - technically a smartphone is both a computer and a telephone, but by doing it the above way, it doesn't matter, as each is simply a product and a set of user-defined attributes. 

Essentially this is the same answer as @Edgar's implementation