Parse error: syntax error, unexpected 'public' (T_PUBLIC) [closed]

此生再无相见时 提交于 2019-12-01 22:41:56

问题


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?:)


回答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.




回答2:


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




回答3:


This is certainly an error in your code, and this is exactly why you should not edit core files as you have here.

You can copy the file you hanged into the local name space from 'core' and then copy the original Magento file back over the core version.

This will allow you to revert easily if you make a mistake.

I would also recommend to get a decent IDE which will show u any coding errors such as missing brackets etc. try something like netbeans or eclipse for excellent warnings when u make simple mistakes



来源:https://stackoverflow.com/questions/21648506/parse-error-syntax-error-unexpected-public-t-public

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!