Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only variables should be passed by reference

Tags:

php

class

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.

like image 900
Cameron Ball Avatar asked Dec 04 '12 08:12

Cameron Ball


1 Answers

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 );
like image 74
Salketer Avatar answered Sep 18 '22 13:09

Salketer