[Big edit, the question is better in this way]
I would like to find a shortcut (without NOTICE) for this code :
if( !empty( $long_var['with']['useless']['long']['argument'] ) )
$long_var['with']['useless']['long']['argument'] =
Custom::myParsing($long_var['with']['useless']['long']['argument']);
As you can see I've got a long var to process, and I don't want to bring it around... (as it's not an isolate case in my code, I want something "clean")
For now I use this :
if( !empty( $long_var['with']['useless']['long']['argument'] ) ){
$lnArgument = &$long_var['with']['useless']['long']['argument'];
$lnArgument = Custom::myParsing($lnArgument);
}
This could be the best, but it bring back a Error before php5.5 and a Notice after :
if( !empty( $lnArgument = &$long_var['with']['useless']['long']['argument'] ) )
$lnArgument = Custom::myParsing($lnArgument);
What is the use of checking empty
in an assignation, even with PHP 5.5? You are assigning something (maybe a NULL, because the expression does not exist and you also got a NOTICE: undefined index
) to a variable. You are defining that variable and then checking for empty? Do you know what 'empty' means when checking a variable? First checks if the variable exists and then checks whether that variable equals FALSE. In your case, the variable will always exist (you created it just there). So, you are actually only checking if that variable equals FALSE.
tl;dr:
You can safely replace the empty with a simple assignation, and let the if
find if what was assigned equals FALSE or not:
if( $lnArgument = &$long_var['with']['useless']['long']['argument'] )
$lnArgument = Custom::myParsing($lnArgument);
(and you will get Notices, but you already know that)