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

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...