Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "?:" mean in PHP? [duplicate]

Tags:

operators

php

While browsing the code of an open source PHP library I spotted this line:

$path = $path ?: $this->guessPackagePath();

This is not the ternary operator like it usually apprears. Would anyone explain what is going on in it?

like image 522
Desmond Hume Avatar asked Jul 22 '26 10:07

Desmond Hume


1 Answers

It's a shortcut for

$path = $path ? $path : $this->guessPackagePath();

which comes from PHP 5.3

like image 88
xdazz Avatar answered Jul 23 '26 23:07

xdazz