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

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c