未初始化的字符串偏移量:-1引用带花括号的单个字符串字符时

I have this code:

$len = strlen($string);

if ($string{$len-1} == '-') {
    // Do stuff...
}

However I get the following NOTICE error:

Uninitialized string offset: -1

When I var_dump($len-1) the value I get:

int 3

When I var_dump($string) I get:

string 'bobo' (length=4)

So could anyone tell me why this is causing a NOTICE error?

To prevent notice add additional condition to if statement:

$len = strlen($string);

if ($len > 0 && $string{$len-1} == '-')
    // Do stuff...
}

or use substr function:

if (substr($string, -1) == '-') {
    // Do stuff...
}
$len = strlen($string);
if(isset($string{$len-1})){
if ($string{$len-1} == '-') {
// Do stuff...
}
}