3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); namespace App { class Product { private $id; private $name; private $volumes; /** * Product constructor. * @param int $id * @param string $name * @param array $volumes * @throws \InvalidArgumentException */ public function __construct(int $id, string $name, array $volumes) { $this->id = $id; $this->name = $name; if (count($volumes) === 0) { throw new \InvalidArgumentException('Your product must have 1 product at least.'); } $this->volumes = $this->prepareVolumes($volumes); } private function prepareVolumes(array $volumes) { foreach ($volumes as $volume) { $volume->setProduct($this); } return $volumes; } } class Volume { protected $id; protected $product; protected $description; public function __construct(string $description) { $this->description = $description; } public function setProduct(Product $product) { $this->product = $product; } } class ProductTest { public function __construct() { $volume1 = new Volume('part-1'); $volume2 = new Volume('part-2'); $volume3 = new Volume('part-3'); $product = new Product(1, 'BED', [$volume1, $volume2, $volume3]); $invalidProduct = new Product(2, 'Table', []); } } return new ProductTest(); }
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
Fatal error: Uncaught InvalidArgumentException: Your product must have 1 product at least. in /in/t7JqO:25 Stack trace: #0 /in/t7JqO(66): App\Product->__construct(2, 'Table', Array) #1 /in/t7JqO(70): App\ProductTest->__construct() #2 {main} thrown in /in/t7JqO on line 25
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Warning: Unsupported declare 'strict_types' in /in/t7JqO on line 2 Catchable fatal error: Argument 1 passed to App\Volume::__construct() must be an instance of App\string, string given, called in /in/t7JqO on line 61 and defined in /in/t7JqO on line 46
Process exited with code 255.

preferences:
111.6 ms | 408 KiB | 5 Q