Question from the PHP8 test

PHP code that throws a TypeError

Hard

What will this code display?

<?php

class Foo
{
    private ?string $bar;

    public function setBar(?string $secondLine): void
    {
        $this->bar = $secondLine;
    }

    public function getBar(): ?string
    {
        $this->bar;
    }
}

$address = new Foo();
$address->setBar(null);
echo $address->getBar() ?? 'john doe';
Author: W3D TeamStatus: PublishedQuestion passed 1117 times
Edit
2
Community EvaluationsNo one has reviewed this question yet, be the first!