可变的外部范围

时间:2012-01-26 19:05:22

标签: php variables scope

以下代码中的$base变量显然超出了范围,但$urlS$urlE变量不是?有人可以解释为什么会这样吗?

class Yahoo {
    //Code below to retrieve live currency rates from yahoo
private static $base = 'USD';
private static $urlS = LIVE_FEED_YAHOO;
private static $urlE = '=X&f=l1';
private $rate;

public function __construct($toCurr) {
$url = self::$urlS.$base.$toCurr.self::$urlE;

1 个答案:

答案 0 :(得分:5)

您需要在self::之前加入$base,就像使用$urlS$urlE一样:

$url = self::$urlS . self::$base . $toCurr . self::$urlE;