function convert($currencyType)
{
$that = $this;
return $result = function() use ($that)
{
if (!in_array($currencyType, $this->ratio))
return false;
return ($this->ratio[$currencyType] * $this->money); //a float number
};
}
$currency = new Currency();
echo $currency->convert('EURO');
どういうところが間違っていますか?Closureクラスのオブジェクトをfilenameの文字列に変換できませんでした。
私は、エラーメッセージが出てい:
Catchable fatal error: Object of class Closure could not be converted to string
あなたの 'convert()'関数は関数を返します。それから、それを 'echo()'することによって文字列に変換しようとしています。 – landons
しかし、クロージャは$ resultにfloat/falseを返しますか? –
そして、Closure内の '$ this'参照は' $ that'でなければなりません。彼らは5.4の考えでそれを変えたかもしれない。わからない。 – landons