语法错误,意外的'public' (T_PUBLIC)

时间:2021-12-24 01:15:25

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管理页面的“重定向基础url”选项中更改了一些内容。然而,事情并没有那么顺利。之后我得到了以下错误:

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

解析错误:语法错误,出乎意料的“公共”(T_PUBLIC).... / public_html / app /代码/核心/法师/核心/模型/配置。php在第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?:)

我自己也不能解决这个问题,因为我是个菜鸟。有人能帮我一下吗?

3 个解决方案

#1


14  

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.

我忘记关闭它上面的函数了,也就是说,}丢失了,所以它就像在另一个函数中定义一个函数。你检查过了吗?

#2


4  

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

您需要在类中使用它,或者删除公共词。

#3


0  

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.

您可以从“core”中将挂起的文件复制到本地名称空间中,然后将原始的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,它将向您显示任何编码错误(如缺少括号等)

#1


14  

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.

我忘记关闭它上面的函数了,也就是说,}丢失了,所以它就像在另一个函数中定义一个函数。你检查过了吗?

#2


4  

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

您需要在类中使用它,或者删除公共词。

#3


0  

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.

您可以从“core”中将挂起的文件复制到本地名称空间中,然后将原始的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,它将向您显示任何编码错误(如缺少括号等)