Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

php - Only variables should be passed by reference

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...