2

Strict standards: Only variables should be passed by reference in C:\xampp\htdoc s\EliteFifa2\src\EliteFifa\Bundle\DataFixtures\ORM\MatchFixtures.php on line 70

Line 70 is referring to this line:

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

I don't understand what is going wrong because the following algorithm works in a normal PHP page.

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;
    }
}
Jonathan
  • 3,016
  • 9
  • 43
  • 74
  • 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:39

1 Answers1

2

This should fix your issue:

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

Edit

Note in the array_shift() docs that the $array argument is passed by reference (denoted with &) because the function modifies the array directly.

mixed array_shift ( array &$array )

You are getting an E_STRICT message. I'n not sure what version of PHP you are using here, but the same operation on my machine raises a fatal error (I'm using 5.5).

Darragh Enright
  • 13,676
  • 7
  • 41
  • 48
  • No problem! Additionally, I guess devmode Symfony2 sets error reporting to its max possible (something like `E_ALL|E_STRICT`, and I assume your PHP installation probably has a different default, hence why the error does not appear in your other script. – Darragh Enright Apr 21 '14 at 16:54