What does this symbol mean “?->” in php, within an object or null value [duplicate]

谁说胖子不能爱 提交于 2020-06-28 03:41:20

问题


Could you please explain what does the operator ?-> do in PHP, since I have this piece of code:

$drive = $objDrive?->func?->getDriver()?->value;

回答1:


For the moment, it's just a proposal, you can find it enter link description here. It's the NullSafe Operator, it returns null in case you try to invoke functions or get values from null... Example

$objDrive = null;
$drive = $objDrive?->func?->getDriver()?->value; //return null
$drive = $objDrive->func->getDriver()->value; // Error: Trying to get property 'func' of non-object


来源:https://stackoverflow.com/questions/62178354/what-does-this-symbol-mean-in-php-within-an-object-or-null-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!