【发布时间】:2013-10-17 16:45:53
【问题描述】:
我是 PHP 新手,遇到一个问题,我似乎无法修复或找到解决方案。
我正在尝试创建一个辅助函数,该函数将返回一个“对象”,其中填充了从 XML 文件中提取的信息。这个名为 functions.php 的辅助函数包含一个 getter 方法,该方法返回一个“类”对象,其中填充了来自 SVN log.xml 文件的数据。
每当我尝试使用include 'functions.php'; 导入此文件时,在该行运行之后,调用函数的页面都不会是空白的。
我做错了什么?
下面是 functions.php 辅助方法和类声明的样子:
<?php
$list_xml=simplexml_load_file("svn_list.xml");
$log_xml=simplexml_load_file("svn_log.xml");
class Entry{
var $revision;
var $date;
}
function getEntry($date){
$ret = new Entry;
foreach ($log_xml->logentry as $logentry){
if ($logentry->date == $date){
$ret->date = $logentry->date;
$ret->author = $logentry->author;
}
}
return $ret;
}
【问题讨论】:
-
在
function getEntry($date){中声明global $log_xml, $list_xml; -
@TamilSelvan 我尝试在 getEntry() 函数中添加您的建议,但仍然存在同样的问题。它与我导入functions.php的方式有什么关系吗?
-
在functions.php文件中包含Entry类
-
您的文件布局到底是什么?是不是functions.php中的getEntry函数,Entry类是一个单独的文件,而xml加载在主文件中?您的包含如何适合执行?
-
@TamilSelvan 我不确定你在functions.php中包含Entry类是什么意思,我应该怎么做?
标签: php object methods import include