-1
if($player[$x]->name == $p->name || $player[$x]->name == $target) unset $player[$x]; //<-- line 215

commenting out this line removes the error:

PHP Parse error:  syntax error, unexpected T_VARIABLE, expecting '(' in /path/script.php on line 215

But I don't see were it's expecting a (, am I missing something obvious?

dukevin
  • 22,384
  • 36
  • 82
  • 111
  • [What is the difference between a language construct and a “built-in” function in PHP?](http://stackoverflow.com/questions/1180184/what-is-the-difference-between-a-language-construct-and-a-built-in-function-in) – Jared Farrish Jan 17 '12 at 01:36

3 Answers3

9

unset() is a language construct that requires parentheses; you must use unset($player[$x]);.

Interrobang
  • 16,984
  • 3
  • 55
  • 63
5

unset is a function, you need to call it with parentheses, like this: unset( $player[ $x ] )

you'd better separate your code to different lines to see where the problem is more easily.

abresas
  • 835
  • 6
  • 7
  • 2
    `unset()` is a language construct invoked like a function. – alex Jan 17 '12 at 01:38
  • 1
    +1.5 for suggesting OP separate code onto multiple lines for readability, -0.5 for saying unset is a function, when it is actually a language construct – Bailey Parker Jan 17 '12 at 02:29
3

Unset requires the parentheses:

if($player[$x]->name == $p->name || $player[$x]->name == $target) unset($player[$x]);
jValdron
  • 3,408
  • 1
  • 28
  • 44
  • 3
    This is completely pedantic (aka ignore me), but in the interest of completeness, I found while writing my answer that `unset()` is not actually considered a function. From the PHP manual: "Note: Because this is a language construct and not a function, it cannot be called using variable functions". http://php.net/unset – Interrobang Jan 17 '12 at 01:37