昨天我完成了课程的建设,其中我使用了__call
方法(前几天介绍过)。但它运行正确,直到我使用__call
方法。如何解决它? - 变量包含的内容应该是
其所有代码是
public function __call($Function, array $Parameters)
{
if(method_exists($this, $Function))
{
call_user_func_array(array($this, $Name), $Parameters);
}
else
{
try
{
if(!preg_match('/[A-Za-z]_Style|Attribute/i', $Function))
{
throw new MarC_Exception(...);
}
}
catch(MarC_Exception $Exception)
{
$Exception -> ExceptionWarning(...);
}
$Function = explode('_', $Function);
$Function[0] = strtolower($Function[0]);
...
$Options = array('Style', 'Attribute');
if($Function[1] == $Options[0])
{
if(strtolower($Function[0]) == $this -> Elements['top'])
{
array_unshift($Parameters, $Function[0]);
call_user_func_array(array($this, 'Set_AllElementStyles'), $Parameters);
}
else
{
if($this -> Check_StyleName($Parameters[0]))
{
array_unshift($Parameters, $Function[0]);
call_user_func_array(array($this, 'Set_AllElementStyles'), $Parameters);
}
}
}
else
{
if(strtolower($Function[0]) == $this -> Elements['top'])
{
array_unshift($Parameters, $Function[0]);
call_user_func_array(array($this, 'Set_AllElementAttributes'), $Parameters);
}
else
{
if($this -> Check_AttributeName($Parameters[0]))
{
array_unshift($Parameters, $Function[0]);
call_user_func_array(array($this, 'Set_AllElementAttributes'), $Parameters);
}
}
}
}
}
,但问题是,(此时)在preg_match
使用。在那里他看到(我不知道为什么)变量函数的内容是Set_AllElementStyles(我在call_user_func_array下面调用)代替(例如)Body_Style。
如果地方为代码echo $Function
,看看到底发生了什么,它会调用
Body_style
如果是在功能代码开头或内如果分支的if-else语句Body_Style
和Set_AllElementStyles
如果在if-else的其他分支中
我在哪里发生了导致此问题的错误?(?如何解决此问题)
编辑1:类RootAssembler_Html的对象的 实施例(即抽象类UniqueAssembler的最终覆盖),具有__call
用法在一起。
$VMaX = new MarC\RootAssembler_Html();
$VMaX -> Set_ExportWay();
$VMaX -> Set_Content();
$VMaX -> Set_Content($Text);
$VMaX -> Body_Style('background-color', '#ABCDEF');
$VMaX -> Body_Attribute('id', 'test');
$VMaX -> Execute();
输出:
<html>
<head>
/* some text that is not set in the first usage of method Set_Content */
</head>
<body id='test' style="background-color: #ABCDEF;">
/* some text that was set in the second usage of method Set_Content */
</body>
</html>
我认为你应该提供一些较短的工作代码,这样我们就可以更容易地看到问题所在 - 并且你会告诉我们你尝试了一些调试......顺便说一句。你知道你的正则表达式/ [a-z] \ _ Style | Attribute/i匹配:单词“属性”还是一个字母后跟'_'和“样式”? –
@JanLegner:问题不在于正则表达式本身(即使它可能错误)。问题是'Set_AllElementStyles'不应该出现在那里。 –
@Václav如何调用具有参数的'__call'以及实际输出和期望输出的示例? – divaka