【发布时间】:2011-11-24 09:52:02
【问题描述】:
我想知道PHP中是否有可能做以下事情;
<?php
class boo {
static public $myVariable;
public function __construct ($variable) {
self::$myVariable = $variable;
}
}
class foo {
public $firstVar;
public $secondVar;
public $anotherClass;
public function __construct($configArray) {
$this->firstVar = $configArray['firstVal'];
$this->secondVar= $configArray['secondVar'];
$this->anotherClass= new boo($configArray['thirdVal']);
}
}
$classFoo = new foo (array('firstVal'=>'1st Value', 'secondVar'=>'2nd Value', 'thirdVal'=>'Hello World',));
echo $classFoo->anotherClass::$myVariable;
?>
预期输出: Hello World
我收到以下错误; Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM
我在 Google 上搜索过,它与$classFoo->anotherClass::$myVariable中的冒号(双点)有关
我不想费尽心思去改变我的其他课程。反正有这个问题吗?
提前感谢您的帮助。
P.S.我只是不想为此浪费几个小时来寻找解决方法。我昨天已经花了 2.5 个小时来更改几乎整个 Jquery,因为客户想要更改,而今天早上我被要求收回更改,因为他们不想使用它(他们改变了主意)。我现在只是想避免大的变化。
【问题讨论】:
标签: php class variables static constants