Symfony2 DataFixtures错误? "只有变量应该通过引用传递"

时间:2014-04-21 16:41:24

标签: php symfony

  

严格的标准:只有变量才能通过引用传递   C:\ XAMPP \ htdoc   小号\ EliteFifa2的\ src \ EliteFifa \包\ DataFixtures \ ORM \ MatchFixtures.php   在第70行

第70行是指这一行:

$lastHomeTeam = array_shift(array_splice($homeTeams, 1, 1));

我不明白出现了什么问题,因为以下算法适用于普通的PHP页面。

class MatchFixtures extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
{
    private $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    public function load(ObjectManager $manager)
    {
        $teams = array(0, 1, 2, 3);
        $worldSeason1 = $this->getReference("WorldSeason1");
        $league1 = $this->getReference("League 1");

        $fixtures = $this->createFixtures($teams, $worldSeason1, $league1);
    }

    private function createFixtures($teams, $season, $competition)
    {
        $teamsCount = count($teams);
        $rounds = $teamsCount - 1;
        $matchesPerRound = $teamsCount / 2;

        $awayTeams = array_splice($teams, $matchesPerRound);
        $homeTeams = $teams;

        $fixtures = array();
        for ($r = 0; $r < $rounds; $r++) {
            for ($m = 0; $m < $matchesPerRound; $m++) {
                $homeTeam = $homeTeams[$m];
                $awayTeam = $awayTeams[$m];

                $fixtures[$r][$m]["home"] = $homeTeam;
                $fixtures[$r][$m]["away"] = $awayTeam;
            }
            $lastHomeTeam = array_shift(array_splice($homeTeams, 1, 1));
            array_unshift($awayTeams, $lastHomeTeam);

            $lastAwayTeam = array_pop($awayTeams);
            array_push($homeTeams, $lastAwayTeam);
        }

        return $fixtures;
    }
}

1 个答案:

答案 0 :(得分:2)

这可以解决您的问题:

$spliced = array_splice($homeTeams, 1, 1);
$lastHomeTeam = array_shift($spliced);

修改

请注意array_shift() docs $array参数是通过引用传递的(用&表示),因为该函数直接修改了数组。

  

mixed array_shift(array&amp; $ array)

您收到了E_STRICT条消息。我不确定你在这里使用的PHP版本,但我机器上的相同操作会引发致命错误(我使用5.5)。