“PHP面向对象”;严格的标准:只有变量才能通过引用传递到";

“PHP面向对象”;严格的标准:只有变量才能通过引用传递到";,php,oop,Php,Oop,所以我已经读了太多的问题,也读了,但仍然无法理解为什么我会看到这些 所以我有一个PHP类 class ProfileTranslator extends EntityTranslator { public function getProfile($identifier) { try { $stmt = $this->dbConn->prepare("CALL get_profile(?)");

所以我已经读了太多的问题,也读了,但仍然无法理解为什么我会看到这些

所以我有一个
PHP类

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
    }
}
错误:

(!)严格标准:只能通过引用传递变量 在ProfileTranslator.php中 在线119


这个代码有什么问题?
$profile
不是一个变量吗?

$profile
是一个变量,但它包含一个对象,一个由
$profile->setProfileId
访问的对象

$profile = new entity\Profile();
严格来说,不应通过引用传递,如在函数中:

$this->getAccount($profile);

您收到的错误消息是什么?请尝试将$profile分配给assignProfileData()中的一个变量,然后将该变量传递给getAccount()@Jacob我已经尝试过了,但仍然看到警告。可能值得注意的是,代码仍然有效,所有数据都已加载,我只是看到了此警告,并想了解代码生成此警告的原因。此错误通常发生在将一个函数的结果传递到另一个函数时,例如将返回数组的函数传递到需要数组变量的函数中。根据严格的设置,这是无效的。但我看不出你的代码是如何做类似的事情的,所以我不确定它在这里是如何应用的。@davidethell是的,我有点困惑。我今天开始分解代码,之前,我只将
profileId
传递给
getAccount
函数,并返回一个
account
,然后将其设置到
profile
,但是我意识到我实例化的对象比我需要的要多,所以我想我可以传递
配置文件
对象来拾取片段。显然这并不理想。只是不知道为什么。。。