As stated elsewhere on this question, in PHP 7.2 get_class
manual states:
Note: Explicitly passing NULL as the object is no longer allowed as of PHP 7.2.0. The parameter is still optional and calling get_class() without a parameter from inside a class will work, but passing NULL now emits an E_WARNING notice.
As you found with your own answer.
However you stated:
So downgrading php version to 7.1 solved the problem.
Downgrading PHP is not usually the best or long term way to solve problems*; instead you need to wrap the get_class
in a checker function such as is_object
, or inversely, is_null
:
$baz = new class();
$className = false; // catch all if $baz is not an object
if(is_object($baz)){
$className = get_class($baz);
}
- As stated by Nicco Hasse
If this problem occurs within Symfony code, just changing the Symfony code is not a good idea. And as upgrading Symfony is not an option, as stated in the OPs answer, staying on 7.1 seems to be the best solution
I would say that while it may be fiddly to "fix" Symphony code, I would suggest adding the qualifier is_object
to the Symphony code and then updating to the latest Symphony version when it comes out (which I hope would fix this issue).
Note: Explicitly passing NULL as the object is no longer allowed as of PHP 7.2.0. The parameter is still optional and calling get_class() without a parameter from inside a class will work, but passing NULL now emits an E_WARNING notice.