1
votes

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

$drive = $objDrive?->func?->getDriver()?->value;
1
The answer to this question should be placed in What does this symbol mean?.John Conde
as far as I know, it is a new operator in the programming language, thanks for your suggestionOscar Gallardo
The code you have written there will not work in any released version of PHP, and may or may not ever do so. The feature was only officially proposed yesterday, and hasn't even been discussed yet.IMSoP

1 Answers

3
votes

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