严格标准:在IF语句中只能通过引用传递变量


Strict Standards: Only variables should be passed by reference in with IF statement

遇到以下问题,我还没有找到合适的答案。。。

严格标准:在…中只有变量应通过引用传递。。。代码为:公共函数查询($query){

    mysql_query('SET NAMES ''utf8''', $this->connection);
    $result = mysql_query($query, $this->connection);
    $this->counter++;
    if (!$result) {
        throw new Exception('A MySQL error (#' . mysql_errno() . ' / ' . mysql_error() . ') occured in the following query: ''' . $this->parseQuery($query) . '''');
    }
    if (in_array(strtoupper(array_shift(explode(' ', $this->parseQuery($query)))), array('SELECT', 'SHOW', 'EXPLAIN', 'DESCRIBE'))) 
    {
       $this->queries[] = $result;
    } 

这部分的问题是:if(in_array(strtoupper(array_shift(explose('',$this->parseQuery($query))),array('SELECT','SHOW','EXPLAIN','DESCRIBE'))

我试着重写,这样它就不再"嵌套"了。。。但没有运气。我可以在这方面得到一些帮助,因为我的编程技能不够好

它在array_shift中只接受变量引用:

$arr = explode(' ', $this->parseQuery($query));
if (in_array(strtoupper(array_shift($arr)), array('SELECT', 'SHOW', 'EXPLAIN', 'DESCRIBE'))) 
{
    $this->queries[] = $result;
}

这将工作

试试这个:

<?php
    mysql_query('SET NAMES ''utf8''', $this->connection);
    $result = mysql_query($query, $this->connection);
    $this->counter++;
    if (!$result) {
        throw new Exception('A MySQL error (#' . mysql_errno() . ' / ' . mysql_error() . ') occured in the following query: ''' . $this->parseQuery($query) . '''');
    }
    $arr = array_shift(explode(' ', $this->parseQuery($query)));
    if (in_array(strtoupper($arr), array('SELECT', 'SHOW', 'EXPLAIN', 'DESCRIBE'))) 
    {
       $this->queries[] = $result;
    }