2

Been quite some time since I did PHP; but, something that I believe used to work doesn't seem to be working PHP 7

$list = array ();
while ( ($data = fgetcsv($handle) ) !== FALSE ) {
  $row = array ();
  $row[0] = 1;
  array_push(&$list,$row);
}

This seems to fail due to "Parse error: syntax error, unexpected '&'" however if I take the & off the $list array won't have the $row array inside of it due to scope. Has this changed in PHP 7 on how to handle this?

6
  • try changing !== to != . You don't need the extra '=' for a Boolean comparison. Commented May 24, 2018 at 22:04
  • 1
    There shouldn't be a scope issue inside the example probably something else. Commented May 24, 2018 at 22:04
  • There's no need for &. Once you create a reference variable you just use it normally. Commented May 24, 2018 at 22:07
  • Take the & off then debug the script. Commented May 24, 2018 at 22:09
  • Call-time pass by reference has been removed in PHP 5.4 (iirc). Sounds like a really long time. Commented May 24, 2018 at 22:10

1 Answer 1

3

If you're trying to push a reference to $row, it should be:

$list[] = &$row;

Reference syntax can't be used in function calls, only assignments. Assigning to an array followed by [] is equivalent to array_push().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.