0

This function is part of a class. I get the "else" to work if its more than 6 char but the first echo keeps giving me

"Parse error: syntax error, unexpected '"Name... "' (T_CONSTANT_ENCAPSED_STRING)"

no matter what I do

public function showOutput(){
    if (strlen($this->name) < 6) { 
  echo " Name needs more than 5 characters ";
    } else  {
    echo "Name " . $this->name;
        }
    }

EDIT I copied the code from one editor to notepadd++ and for some reason it cashed a " ' " on the line. It bothered me for an hour and a half hence signing up and asking. Thank you and sorry for the trouble. I did read the duplicate answers but none helped hence why I asked.

Thank you

PHPn00b
  • 3
  • 3
  • 3
    you need to end lines with a semi-colon.. – treyBake Apr 05 '18 at 12:41
  • 2
    you miss ";" (semicolon) in echo " Name needs more than 5 characters " – Dave Apr 05 '18 at 12:47
  • Its there and i still get the same error – PHPn00b Apr 05 '18 at 12:49
  • Are you sure that $this->name is accessible within the context of this function? Try var_dump($this->name) it just to see the function can access it. – GustavMahler Apr 05 '18 at 12:57
  • If the semicolon is in your code, then please edit your question to include it. The code that you have posted will not run and will return an error just like the one you describe because `echo " Name needs more than 5 characters "` needs to have a semicolon at the end. – mtr.web Apr 05 '18 at 12:59

0 Answers0