0

My PHP syntax highlighter / intellisense is telling me that the & of &$cases in the line

$thisTable = $work_type === WorkTypes::Study ? &$cases : &$projs);

is an unexpected token. What I'm trying to do is create an alias for either my $cases or $projs object depending on whether $work_type === WorkTypes::Study.

3 Answers3

0

You are missing a parenthesis:

$thisTable = ($work_type === WorkTypes::Study ? &$cases : &$projs);
ceiroa
  • 5,833
  • 2
  • 21
  • 18
Halayem Anis
  • 7,654
  • 2
  • 25
  • 45
0

Sometimes a missing ( bracket could kill you, happens to the best of us.

$thisTable = ($work_type === WorkTypes::Study ? &$cases : &$projs);
DirtyBit
  • 16,613
  • 4
  • 34
  • 55
0

The highlighter is right: the reference operator does not work inside a ternary operator because the =& is atomic (although the spaces don't seem to matter too much). Use this instead:

$work_type === WorkTypes::Study ? $thisTable = &$cases : $thisTable = &$projs;

(and as others have mentioned: either no brackets or both)

See also this SO answer.

Community
  • 1
  • 1
Marten Koetsier
  • 3,389
  • 2
  • 25
  • 36
  • Thanks! It appears that this bit of code is what was causing my entire page to not renderr. –  Aug 27 '15 at 16:46
  • You're welcome. If it works, please mark the answer as accepted (see also [this guide](http://stackoverflow.com/help/someone-answers). – Marten Koetsier Aug 28 '15 at 10:45