Parse error: syntax error, unexpected 'public' (T_PUBLIC)

31,915

Solution 1

I had same problem with my code when I was working in an Opencart Project. After several hours of frustration I realized that the cause of this issue was the absence of closure of last function.

I forgot to close the function above it i.e. } was missing so it was like defining a function inside another function. Have you checked if that's the same case with you.

Solution 2

You need to use this in a class, or remove the public word.

Share:
31,915

Related videos on Youtube

user3287603
Author by

user3287603

Updated on December 11, 2020

Comments

  • user3287603
    user3287603 over 3 years

    I changed something in my "redirect base url" options on the magento admin page. However, that didnt work out that well. After that I got the following error:

    Parse error: syntax error, unexpected 'public' (T_PUBLIC) in ..../public_html/app/code/core/Mage/Core/Model/Config.php on line 662

    With the code:

    public function setNode($path, $value, $overwrite = true)
    {
        if ($this->_useCache && ($path !== null)) {
            $sectionPath = explode('/', $path);
            $config = $this->_getSectionConfig($sectionPath);
            if ($config) {
                $sectionPath = array_slice($sectionPath, $this->_cacheSections[$sectionPath[0]]+1);
                $sectionPath = implode('/', $sectionPath);
                $config->setNode($sectionPath, $value, $overwrite);
            }
        }
        return parent::setNode($path, $value, $overwrite);
    }
    

    I cannot figure out the problem myself as Im a rookie with this kind of stuff. Could anybody perhaps help me out?:)

  • user3287603
    user3287603 about 10 years
    I already tried removing the public word. Then it asks me to remove all the public words in the whole file. Doin that leaves me still what an error. I can provide you with the code if that might help, because I have no clue what it could be :$
  • Rohan Kandwal
    Rohan Kandwal over 9 years
    Thanks, this was the problem in my case too. You save me hours of hair pulling. :P
  • elembivos
    elembivos over 9 years
    Oh you're welcome.. Happy to help.
  • Funk Forty Niner
    Funk Forty Niner almost 7 years
    This was the same problem with me also. @elembivos I have to admit and "facepalming" myself that I "should' have popped someone else's code that I tested into my editor "before" running it lol. Oh well, nobody's perfect ;-) Gotta love Google, eh?