The issue is quite simple. I need to return multiple values from a function. How can I do it?
Code is below:
<?php
abstract class Products
{
protected $name;
protected $price;
public function __construct($name, $price)
{
$this->name = $name;
$this->price = $price;
}
public function getName()
{
return $this->name;
}
public function getPrice()
{
return $this->price;
}
}
// A new class extension
class Furniture extends Products
{
protected $width;
protected $height;
protected $length;
public function getSize()
{
// return $this->width;
// return $this->height;
// return $this->length;
// return array($this->width, $this->height, $this->length);
}
}
So as far as I understand, when I return something, it will stop the function, so I understand why I can't just do return three times. An attempt to return an array didn't work. It resulted in an error:
Notice: Array to string conversion
How can I return all three of those?