php 解析错误:语法错误,意外的“公共”(T_PUBLIC)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21648506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Parse error: syntax error, unexpected 'public' (T_PUBLIC)
提问by user3287603
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:
我在 magento 管理页面上的“重定向基本网址”选项中更改了一些内容。然而,这并没有那么好。之后,我收到以下错误:
Parse error: syntax error, unexpected 'public' (T_PUBLIC) in ..../public_html/app/code/core/Mage/Core/Model/Config.php on line 662
解析错误:语法错误,第 662 行上的 ..../public_html/app/code/core/Mage/Core/Model/Config.php 中出现意外的“public”(T_PUBLIC)
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?:)
我无法自己弄清楚问题,因为我是这种东西的菜鸟。有人可以帮我吗?:)
回答by elembivos
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.
当我在 Opencart 项目中工作时,我的代码遇到了同样的问题。经过几个小时的挫折,我意识到这个问题的原因是最后一个函数没有关闭。
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.
我忘了关闭它上面的函数,即
}丢失了,所以就像在另一个函数中定义一个函数一样。你有没有检查过你的情况是否一样。
回答by Farkie
You need to use this in a class, or remove the publicword.
你需要在课堂上使用这个,或者删除这个public词。
回答by Andrew
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.
您可以将挂起的文件从“核心”复制到本地命名空间,然后将原始 Magento 文件复制回核心版本。
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
我还建议获得一个不错的 IDE,它会向您显示任何编码错误,例如缺少括号等。尝试使用 netbeans 或 eclipse 之类的东西,以便在您犯简单错误时获得出色的警告

