【发布时间】:2015-09-24 02:40:19
【问题描述】:
我是 php OOP 的新手,我需要一些帮助来修复以下错误。
PHP 严格标准:在第 30 行的 /home/XXX/public_html/h1.com/includes/Article.class.php 中,只能通过引用传递变量
这里是 Article.class.php 的代码 --> loadByUrl
<?php
class Article extends DBEntity
{
static $table= 'article', $pkey = 'articleID', $db, $fields, $fieldnames;
static $relations= array(
);
function save($model = null)
{
if(($article = $this->loadByUrl($this->getUrl())) && $article->articleID != $this- >articleID)
{
trigger_error("The URL specified for this article is in conflict with another article.");
return false;
}
return parent::save($model);
}
public static function loadByUrl($url, $type = null)
{
$url = trim($url);
$conditions = array("articleURL = '$url'");
if($type)
$conditions[] = "articleType = '$type'";
// Line 30 error
return array_pop(Article::listAll(new DBEListCriteria(implode(' and ', $conditions), null, new DBEListOffset(1))));
}
}
class DBEListCriteria
{
private $condition;
function __construct($condition = '')
{
$this->condition = $condition;
}
function __toString()
{
if(!empty($this->condition))
return ("where " . $this->condition);
return "";
}
function getCondition()
{
return $this->condition;
}
}
class DBEListOffset
{
protected $offset, $limit;
function __construct($limit = 50, $offset = 0)
{
$this->offset = intval($offset);
$this->limit = intval($limit);
}
function __toString()
{
if(!empty($this->offset) && !empty($this->limit))
return " limit {$this->offset}, {$this->limit} ";
else if(empty($this->offset) && !empty($this->limit))
return " limit {$this->limit} ";
else
return "";
}
}
?>
Article::loadByUrl called at initialisation time to get an environment variable into $_ENV[site] array:
if($article = Article::loadByUrl(''))
$_ENV[site]->Article = $article;
我正在使用 PHP5.5
【问题讨论】:
标签: php