Removing the & alone sign will result in Notice: Undefined offset: 4 in What I think you need to do is remove & and suppress any E_NOTICE error with @ ;
$lArray = array('A', 'B', 'C'); $lValue = __isset(@$lArray[4], 'D'); // or @__isset($lArray[4], 'D'); var_dump($lValue); var_dump($lArray); function __isset($aVariable, $aDefault = null) { return isset($aVariable) ? $aVariable : $aDefault ; }
Exit (without E_NOTICE error)
string 'D' (length=1) array 0 => string 'A' (length=1) 1 => string 'B' (length=1) 2 => string 'C' (length=1)
Another solution is to use another isset for the dispatcher array and the object
$lArray = array('A','B','C'); $lValue = __issetComplex($lArray, 4, 'D'); var_dump($lValue); var_dump($lArray); function __issetComplex($mixed, $key, $aDefault = null) { if (is_array($mixed)) return array_key_exists($key, $mixed) ? $mixed[$key] : $aDefault; if (is_object($mixed)) return isset($mixed->key) ? $mixed->key : $aDefault; return $aDefault; }
Finally, you can simply override the PHP isset function yourself override_function
source share