Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...