#Bob Exercise in PHP - Test 1 Fails

4 messages · Page 1 of 1 (latest)

vivid bramble
#

Hello everyone! I've been trying to figure this out but I don't know what it is going on.
Failed Test 1 - testStatingSomething

CODE RUN
$this->assertEquals("Whatever.", $this->bob->respondTo("Tom-ay-to, tom-aaaah-to."));
TEST ERROR
BobTest::testStatingSomething
ParseError: syntax error, unexpected token "public", expecting end of file
/mnt/exercism-iteration/Bob.php:5

I've tested locally in my computer with the input "Tom-ay-to, tom-aaaah-to." and it works as expected.
I just want to make sure is not a bug. I must have been missing something.

Thank you!

`<?php

declare(strict_types=1);

public function respondTo(string $str): string
{
$output = "";

    if (strtolower($str) == $str) {
        if (mb_strrchr($str, '?') == true) {
            $output = 'Sure.';
        }
    } elseif (strtoupper($str) == $str) {
        if (mb_strrchr($str, '?') == true) {
            $output = "Calm down, I know what I'm doing!";
        } else {
            $output = 'Whoa, chill out!';
        }
    } elseif (trim($str) == "") {
        $output = 'Fine. Be that way!';
    } else {
        $output = 'Whatever.';
    }
    return $output;
}

`

short jay
#

Haven't tested this, but i see a space before the public function, could that be it?

haughty terrace
#

Is there supposed to be a > at the end to match the open > ?

weary plaza
#

You can’t have public functions in the global scope. Visibility modifiers are only valid inside the context of a class/interface/trait