Question from the PHP8 test

Create a class Foo with a public property amount and a constructor that takes a Currency object and an integer.

Easy

Is this code valid?

<?php

class Currency
{}

class Foo
{
    private int $amount;
 
    public function __construct(
        public Currency $currency,
        int $amount,
    ) {
        $this->amount = $amount;
    }
}

var_dump(new Foo(new Currency, 200));
Author: W3D TeamStatus: PublishedQuestion passed 970 times
Edit
1
Community EvaluationsNo one has reviewed this question yet, be the first!