【发布时间】:2015-05-13 19:44:42
【问题描述】:
这里我导入了包含 getAllFiles() 函数的 files.class.php 类:
include_once('lib/files.class.php');
我在这里调用函数:
<?php
$files = new Files($db);
$jsonEncoding = json_encode($files->getAllFiles());
$jsonFile = fopen("jsonEncoded.json", "w") or die ("Unable to open file!");
fwrite($jsonFile, $jsonEncoding);
$contentOfFile = file_get_contents('./jsonEncoded.json');
echo $contentOfFile;
fclose($jsonFile);
?>
这是 getAllFiles() 函数:
public function getAllFiles() {
if (!($stmt = $this->connection->prepare("SELECT ID, Latitude, Longitude, Name, Radius FROM Files"))) {
$this->lastError = 'Failed to prepare query: ('.$this->connection->errno.') '.$this->connection->error;
return false;
} else {
// Execute the query and store the result set
$stmt->execute();
$stmt->store_result();
// Bind the results to variables
$stmt->bind_result($id, $latitude, $longitude, $name, $radius);
$results = array();
// Keep fetching rows
while ($stmt->fetch()) {
// Add to array
$results[] = array(
'ID' => $id,
'Latitude' => $latitude,
'Longitude' => $longitude,
'Name' => $name,
'Radius' => $radius,
);
}
// Return the results array
return $results;
}
}
我收到以下错误:
致命错误:在第 83 行的 /var/www/localhost/htdocs/mbax4cl3/groupproject/map.php 中调用未定义的方法 Files::getAllFiles()
谢谢!
【问题讨论】:
-
第 83 行是什么?我赌的是一个未定义的函数。
-
确认这个方法实际上是在一个名为 Files 的类中?
-
该方法在一个名为 Files 的类中,我确定。
-
这是在第 83 行:$jsonEncoding = json_encode($files->getAllFiles());
-
当你
var_dump($files);时会发生什么?
标签: php function methods undefined call