有人能告诉我为什么这段代码不起作用吗?这似乎是完成所提议任务的最有效方法,我不明白为什么我不断收到错误 - 即使我反转了 Key<>Value。
我试图用 static::variables 替换文本字符串/数组中的#tags#,形成一个外部类。
错误:
Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in /home/content/57/10764257/html/marketing/includes/ProcessEmail.class.php on line 5
外部课程:
class MyClass {
public static $firstName = "Bob"; // Initally set as "= null", assigned
public static $lastName = "Smith"; // statically through a call from
} // another PHP file.
主要的 PHP 文件:
// This is the array of find/replace strings
private static $tags = array("#fistName#", MyClass::$firstName,
"#lastName#", MyClass::$lastName);
// This jumps trough the above tags, and replaces each tag with
// the static variable from MyClass.class.php
public static function processTags($message) {
foreach ($tags as $tag => $replace) {
$message = str_replace($tag, $replace, $message);
}
}
但我不断收到这个错误......?
谢谢!