doukan4795 2014-12-17 17:16
浏览 78
已采纳

Symfony 2 ContextErrorException运行Doctrine迁移时,只应通过引用传递变量

When I run my Doctrine Migration I get the following error:

Migration 20141217162533 failed during Execution. Error Runtime Notice: Only variables should be passed by reference

[Symfony\Component\Debug\Exception\ContextErrorException] Runtime Notice: Only variables should be passed by reference

on the $this->validateUsername line. When I comment this out it works fine.

This seems like a very strange runtime error to experience and I cannot see why I am getting this.

public function up(Schema $schema)
{
    foreach ($this->old_users as $old_user) {
        if ($this->validateUsername($old_user['email']) === false or $this->checkDNSRecord($old_user['email']) === false) {
            $this->addSql("INSERT INTO User (email, joined_on, unsubscribed) VALUES ('" . $old_user['email'] . "', '" . $old_user['joined_on'] . "', 0)");
        }
    }
}

/**
 * Validate the username/email address based on the structure (e.g. username@domain.com)
 *
 * @param $email
 *
 * @return bool
 */
public function validateUsername($email)
{
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        // email is NOT valid
        return false;
    } else {
        // email is valid
        return true;
    }
}

/**
 * Validate the MX line of the DNS record for the host of the email address (e.g. @aol.co.uk)
 *
 * @param $email
 *
 * @return bool
 */
public function checkDNSRecord($email)
{
    if (checkdnsrr(array_pop(explode('@', $email)), 'MX')) {
        return true;
    } else {
        return false;
    }
}
  • 写回答

2条回答 默认 最新

  • donglan6967 2014-12-17 23:58
    关注

    The problem is that functions like array_pop takes the array by reference since it changes it's content (removes the last element from the array). Now, you are passing the result of explode directly into array_pop array_pop(explode('@', $email)) therefore, php can't pass that result by reference because it's not a variable. The solution is quite simple, just keep explode result in a temp variable:

    <?php
    /* ... */
    $mailParts = explode('@', $email);
    checkdnsrr(array_pop($mailParts), 'MX');
    /* ... */
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法