【发布时间】:2011-07-26 03:28:10
【问题描述】:
我正在尝试编写一个简单的数据库包装类。我写了一个这样的方法:
public function get_objects($sql, $class_name = null) {
$result = mysql_query( $sql, $this->connection );
$objs = array();
if( $result ) {
while ($obj = mysql_fetch_object($result, $class_name)) {
$objs[] = $obj;
}
mysql_free_result($result);
}
return $objs;
}
如果我在调用此方法时未指定 $class_name,则对 mysql_fetch_object 的调用将失败并出现以下错误:
PHP Fatal error: Class '' not found in ...
问题是我不希望它使用类名。我只是希望它执行默认行为,就好像我没有指定类名一样。
为什么会失败?
【问题讨论】: