Test Question PHP8

PHP code that throws an error.


What will this code display?


class Foo
    private ?string $bar;

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

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

$foo = new Foo();
echo $foo->getBar() ?? 'john doe';
Author: W3D teamStatus : PublishedQuestion answered 795 times
Reviews from developersNo one has evaluated this question yet - be the first!
Your browser is badly|not supported!
We recommend you to use a more modern browser such as Edge, Chrome or Firefox
Know More