4

I was debug my php script and found that the whole bug could be abatracted into below code:

<?php
    $items = "1046";
    if(isset($items['expr']))
    {
        echo "isset\n";
    }
    else
    {
        echo "not set\n";
    }
?>

I think that apprently, 'expr' is not set, but the output is "isset"!

well, when tested under php 5.5.9, the output is "not set", but under php 5.3.10, the output is "isset"!

Is it a bug of php 5.3.10?

Alaya
  • 3,287
  • 4
  • 27
  • 39
  • 9
    In PHP <5.4 `$items['expr']` gets silently converted to: `$items[0]` which access'es the first character of your string and the first character is set. (See: http://stackoverflow.com/q/32562436/3933332) – Rizier123 Oct 22 '15 at 12:11
  • expanding on @Rizier123 comment, if your $items variabile were an array (such as `$items = ["1046"]`), you would correctly reach the `else` branch. Being it a string, and testing for an index, php behaves as Rizier pointed out. – Damien Pirsy Oct 22 '15 at 12:35

0 Answers0