1

So I have read too many of this questions already, and have also read PHP: Passing by reference manual and still cannot figure out why I am seeing this.

So I have a PHP Class

class ProfileTranslator extends EntityTranslator {

    public function getProfile($identifier) {
        try {
            $stmt = $this->dbConn->prepare("CALL get_profile(?)");            
            $stmt->bindParam(1, $identifier, \PDO::PARAM_STR);
            $stmt->execute();
            $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
            unset($stmt);
            $count = count($rows);
            if ($count == 1) {
                $row = $rows[0];
                $profile = new entity\Profile();
                $this->assignProfileData($row, $profile);

                // more stuff below...

    }


    private function assignProfileData($row, $profile) {
        $profile->setProfileId($row['profileid']);
        // do some more ->setXYZ's()
        $this->getAccount($profile); // GETTING ERROR HERE (THIS IS LINE 119)
    }

    private function getAccount($profile) {
        // get the account stuff here
    }
}

Error:

( ! ) Strict standards: Only variables should be passed by reference in ProfileTranslator.php on line 119

What is the problem with this code? Isn't $profile a variable?

samazi
  • 1,161
  • 12
  • 24
  • What is the error message you are getting? – davidethell Apr 28 '14 at 02:23
  • 1
    Try assigning $profile to a variable in assignProfileData() then pass that variable to getAccount() – Jacob Apr 28 '14 at 02:34
  • @Jacob I have tried this and still see the warning. Might be worth noting, the code still works, and all the data is loaded, I am just seeing this warning and would like to understand why my code is producing it. – samazi Apr 28 '14 at 02:42
  • This error usually occurs when you pass the result of one function into another function, such as passing a function that returns an array into a function expecting an array variable. That is invalid according to the STRICT settings. But I don't see how your code is doing something similar so I'm not sure how it applies here. – davidethell Apr 28 '14 at 02:46
  • @davidethell Yeah, I am a bit confused. I started breaking the code up today, previously, I only passed in `profileId` to the `getAccount` function and returned an `account` which I then set into the `profile`, but I realised I was instantiating more objects than I needed so I thought I could just pass the `profile` object along to pick up the pieces. Apparently this is not ideal. Just not sure why... – samazi Apr 28 '14 at 03:32
  • which is the 119th line ? – tereško Apr 28 '14 at 08:07
  • I seriously doubt the notice is raised at the line you have indicated. – Ja͢ck Apr 28 '14 at 08:23
  • Can you provide the actual code, stripped to the bare minimum that shows the error message? That said, I'm not sure what you are doing there. If you are trying to use function parameters as output parameters, please don't but rather return them. You can return multiple values using an array and you can unpack the array using `list()`, which makes it much clearer what goes in and what goes out. That said, why isn't there a single function that creates a profile instance from a DB row? – Ulrich Eckhardt Jun 11 '14 at 05:42
  • possible duplicate of [Strict Standards: Only variables should be passed by reference](http://stackoverflow.com/questions/2354609/strict-standards-only-variables-should-be-passed-by-reference) – Lorenz Meyer Jun 21 '14 at 08:30

1 Answers1

0

$profile is a variable, but it countains an object, one that's accessed by $profile->setProfileId

$profile = new entity\Profile();

which by strict standard should not be passed by reference, as in a function:

$this->getAccount($profile);