Jaxel
Well-known member
Lets say I have an array:
Simple right? Now lets say I'm returning using the following:
Also simple, if the keyed value is true, return true, else false. So for keys 1 and 2, it returns true, and for keys 3, 4 and 5, it returns false. However, here comes in the issue... what happens at key 6? In most other systems I have worked with, a non-existent key returns a defaulted false. Since key 6 doesn't exist, its defined as null.
But in XenForo, it doesn't work the same way. Instead the program will come to a screeching halt and loudly fail with an error about non-existent indexes. Because of this, it forces me to include extra checks for pretty much EVERY instance I use an array...
Is this by design? And why?
Code:
$array = array(
'1' => true,
'2' => '1',
'3' => false,
'4' => '0',
'5' => null
)
Code:
return $array[$key] ? true : false;
But in XenForo, it doesn't work the same way. Instead the program will come to a screeching halt and loudly fail with an error about non-existent indexes. Because of this, it forces me to include extra checks for pretty much EVERY instance I use an array...
Code:
return isset($array[$key]) && $array[$key] ? true : false;
Is this by design? And why?