我在单独的.php文件中定义了三个类:
com_dir.php:
<?php
class com_dir
{
public $name = '';
public $author = '';
public $date = '';
public $version = '';
public $summary = '';
}
?>
com_item.php:
<?php
class com_item
{
public $name = '';
public $type = '';
public $full_path = '';
public $item_vers = array()
}
?>
vers.php:
<?php
class vers
{
public $revision;
public $author = '';
public $info = '';
public $date = '';
}
?>
它们与我的index.php文件位于同一目录中:
<?php
include dirname(__FILE__).'/com_dir.php';
include dirname(__FILE__).'/com_item.php';
include dirname(__FILE__).'/vers.php';
ini_set('display_errors',1);
error_reporting(E_ALL);
$xml_log = simplexml_load_file(dirname(__FILE__).'/svn_log.xml');
$xml_list = simplexml_load_file(dirname(__FILE__).'/svn_list.xml');
//irrelevant filler
$com_list = array();
$rev_list = array();
foreach ($xml_list->list as $list)
{
foreach($list->entry as $entry)
{
if ($entry['kind'] == 'dir' && (!in_array($entry -> $commit[0]['revision'], $rev_list)))
{
array_push($rev_list, $entry -> $commit[0]['revision']);
$temp = new com_dir(); //problem line
$temp->name = $entry->name;
echo("worked");
}
}
}
?>
我收到错误:Fatal error: Class 'com_dir' not found in /home/collin/Desktop/Assignment3.0/index.php on line 52
我没有正确地包含它们以便能够从它们创建类实例吗?
答案 0 :(得分:0)
错误包括com_item.php
。 public $item_vers = array()
中没有尾随分号。如果我将ini_set
和error_reporting
移到我的include语句之前,我会抓住这个。
答案 1 :(得分:0)
将此作为您的路径。
define('BASE_PATH', realpath(dirname(__FILE__)));
require_once BASE_PATH . '/com_dir.php';