Thanks for reading my question

Notice: Uninitialized string offset: 0 in /home/public_html/testing/inc/class/template.engine.class.php on line 779

Line 779 is

 778             $var = $this->PARSEVARS[$value];
 779             IF ( $field{0} == '.' ){
 780                  $field = substr($field, 1);
 781             }

I'm not sure what the {0} is for I couldn't find anything on php.net but anyway the value being passed is as follows is empty

ERROR: [TE ERROR] FIELD0 = Value = SRCH_NOT_ROBOT, field = , param=
So $field{0} appears to be empty.

    could it be a typo in referencing the first index of the $field array?

    $field[0]

    But of course if that was the case the following wouldn't make much sense:

    $field = substr($field, 1);

    Curly braces are used to tell php evaluate what is inside the curly braces, so {0} is just evaluating that integer.

      Actually, if you read this bit in the manual, you'll see that strings can be treated as arrays and that each character is an array item, so $string[0] would mean the first character of the string (assuming $string is a string). As noted, using curly braces is a deprecated manner of achieving the same result.

      The problem, however, seems to be that $field[0] doesn't exist. What you should also be checking is that $field is set (you didn't show us where it was defined) and that it contains the correct type of value (e.g. it doesn't contain FALSE if a function failed).

        Yes as I was searching about it, I came across this example:

        $x="test";
        $y=$x{2};
        echo $y;
        
        //will display "s".

        Thanks for the clarification Brad.

          So what exactly do they mean by curly braces is a deprecated way as of php6 does it mean that it's going away?

          I assume that I should switch to [] brackets and doe something like

          
                    IF ( !empty( $field ) ){
                         IF ( $field[0] == '.' ) $field = substr($field, 1);
                    }
          

          OR

                        IF ( isSet( $field ) ){
                             IF ( $field[0] == '.' ) $field = substr($field, 1);
                        }        

          OR

                        IF (  $field != '' ){
                             IF ( $field[0] == '.' ) $field = substr($field, 1);
                        }        

          Seems to me not using functions when possible is better but not sure which is best in long term.

            rremm2000 wrote:

            So what exactly do they mean by curly braces is a deprecated way as of php6 does it mean that it's going away?

            Yes, it means that using curly braces is a coding practice that is considered out of date and not recommended.

            rremm2000 wrote:

            eems to me not using functions when possible is better

            Are you talking about using isset/empty() compared to the last if() statement? If so, then you may be right, but this isn't a situation when it's "possible" then, since the point of using one of those two is to check that the variable is set first, otherwise you'll generate a notice/warning.

            Also, you can certainly combine the conditions into one if() statement since the condition is evaluated from left to right, ex.

            if(isset($field) && $field[0] == '.')
              Write a Reply...