只有通过引用传递变量 [英] Only variables should be passed by reference

查看:96
本文介绍了只有通过引用传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类:

  class Validator {
private $ validationArray;
private $ washedValues;

public function __construct($ arg1,$ arg2 = NULL){
if(empty($ arg2)){
$ this-> LoadValidatorByName($ arg1);
} else {
$ this-> LoadValidatorFromLeadType($ arg1,$ arg2);
}
}

私有函数LoadValidatorFromLeadType($ lead_type,$ vocabulary){
$ ErrorReporter = new ErrorReporter;
$ taxonomy_term = reset(taxonomy_get_term_by_name($ lead_type,$ vocabulary));

...一些更多的东西

函数taxonomy_get_term_by_name是一个Drupal函数但我遇到的问题是一个PHP。



当这种方法被调用时,PHP抱怨:

 严格警告:只有变量应该通过引用传递Validator-> LoadValidatorFromLeadType()([路径到我的文件]的第32行)
/ pre>

第32行是:

  $ taxonomy_term = reset(taxonomy_get_term_by_name($ lead_type,$ vocabulary)); 

我看了错误,我确定我知道这是什么意思,我无法理解导致此警告的代码有什么问题。

解决方案

重置正在等待变量引用。你传递一个函数结果...

  $ taxonomy_term = taxonomy_get_term_by_name($ lead_type,$ vocabulary); 
$ taxonomy_term = reset($ taxonomy_term);


I have a class:

class Validator {
    private $validationArray;
    private $cleanedValues;

    public function __construct($arg1, $arg2=NULL) {
        if(empty($arg2)) {
            $this->LoadValidatorByName($arg1);
        } else {
            $this->LoadValidatorFromLeadType($arg1, $arg2);
        }
    }

    private function LoadValidatorFromLeadType($lead_type, $vocabulary) {
            $ErrorReporter = new ErrorReporter;
            $taxonomy_term = reset(taxonomy_get_term_by_name($lead_type, $vocabulary));

...some more stuff

The function taxonomy_get_term_by_name is a Drupal function but the issue I am experiencing is a PHP one.

When this method is called PHP complains with:

Strict warning: Only variables should be passed by reference in Validator->LoadValidatorFromLeadType() (line 32 of [path to my file])

Line 32 is ths line with:

$taxonomy_term = reset(taxonomy_get_term_by_name($lead_type, $vocabulary));

I've looked in to the error and I'm pretty sure I know what it means, but I can't understand what is wrong with my code that causes this warning.

解决方案

reset is waiting for a variable reference. You are passing it a function result...

$taxonomy_term = taxonomy_get_term_by_name($lead_type, $vocabulary);
$taxonomy_term = reset($taxonomy_term );

这篇关于只有通过引用传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆