laravel - Correct way to avoid `Undefined index` error (NOT NOTICE!!) with php 7 -
this question has answer here:
- how avoid undefined index 3 answers
i not talking this:
i talking crash, fatal error. not "notice".
edit if caused notice, result crash. question is: how configure laravel, not crash on notices?
i run laravel 5.3 , php 7.
my error:
errorexception in uploadcontroller.php line 149: undefined index:
my code:
if (!plumconstants::$plum_us_states[$state]) { $state = ''; }
referencing constants class:
class plumconstants { public static $plum_us_states = array( 'al' => 'alabama', 'ak' => 'alaska', 'az' => 'arizona', 'ar' => 'arkansas', 'ca' => 'california', // ... ); }
well, that's bit funny no? because doing checking if entry exists
if (!plumconstants::$plum_us_states[$pstate]) {
but somehow php seems panic , crash because there not defined index... when doing , avoiding in code. there way switch odd behavior off? can use isset()
think it's ugly. because isset
not mean not null or empty. nice way this?
if using php7 can using
plumconstants::$plum_us_states[$pstate] ?? false
instead
!plumconstants::$plum_us_states[$pstate]
Comments
Post a Comment