This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
有没有办法用某种安全导航操作符编写以下语句?
echo $data->getMyObject() != null ? $data->getMyObject()->getName() : '';
Run Code Online (Sandbox Code Playgroud)
所以它看起来像这样:
echo $data->getMyObject()?->getName();
Run Code Online (Sandbox Code Playgroud)