0
我有這個類:PHP OOP - 的toString不工作
<?php
class config {
var $config="";
public function __construct($d) {
switch(strtolower(trim($d))) {
case "sql":
$this -> config = array(...);
break;
}
}
public function toString() {
return $this -> config;
}
}
?>
$c = new config("sql");// calling the class
echo $c; //error
我'得到以下錯誤:
(!) Catchable fatal error: Object of class config could not be converted to string in ..
爲什麼不工作?