-3

I was reading a source from laravel project and then i found this line:

$this->crawler() ?: $this->response->getContent()

Does ?: do something special? In php?

I dont remember seeing that in any other place

CarlosCarucce
  • 3,420
  • 1
  • 28
  • 51

1 Answers1

1

Ternary operator :)

Left side determines the course of action if the function called returns anything other than FALSE or 0. If it is false or 0, the right side will be the action taken.

This can also be 'stacked' to perform the first statement in a sequence that results in a value of anything but FALSE or 0. For example:

echo 0 ?: 1 ?: 2 ?: 3; //1
echo 1 ?: 0 ?: 3 ?: 2; //1
echo 2 ?: 1 ?: 0 ?: 3; //2
echo 3 ?: 2 ?: 1 ?: 0; //3
echo 0 ?: 1 ?: 2 ?: 3; //1
echo 0 ?: 0 ?: 2 ?: 3; //2
echo 0 ?: 0 ?: 0 ?: 3; //3
Paul Horn
  • 3
  • 2