How to resolve error Uninitialized string offset: 0 in

3

I'm using PHP Phreeze to create a CRUD application but I'm getting the following message when generating the application, the message is this:

  

Uninitialized string offset: 0 in modifier.lcfirst.php at line 16

The page that has the code looks like this:

function smarty_modifier_lcfirst($s) {
     return strtolower( $s{0} ). substr( $s, 1 );
}

The project page, if anyone is interested, is this: Pheeze

    
asked by anonymous 08.12.2015 / 14:31

1 answer

2

This is because the string does not have the 0 offset. That is, it is empty.

Example:

$a = ''

$a{0}; // PHP error:  Uninitialized string offset: 0

As stated in some comments, you can use the isset function to do this check. You can also use the empty function to know if the string is empty.

You can change the function to the following form:

smarty_modifier_lcfirst($s) { 

    if (empty($s)) return;

    return strtolower( $s{0} ). substr( $s, 1 );
}
    
15.12.2015 / 15:46