- Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- Save the cart using the CartRepository saved!
<?php
class Cart
{
public function save(object $repo = null)
{
if ($repo === null || !$repo instanceof CartRepository) {
throw new Exception('Save the cart using the CartRepository' . "\n");
}
$repo->save($this);
}
}
class CartRepository
{
public function save(Cart $cart)
{
return 'saved!';
}
}
$repo = new CartRepository();
$cart = new Cart();
try {
$cart->save();
} catch (Exception $e) {
echo $e->getMessage();
}
echo $repo->save($cart);