Professional Web Applications Themes

#46365 [NEW]: bug in function array_search - PHP Bugs

From: spabox at hshhhhh dot name Operating system: winxp PHP version: 5.2.6 PHP Bug Type: Arrays related Bug description: bug in function array_search Description: ------------ bug in function array_search: when first element in array is zero, function return zero, but if null, false or sth else returning correct key. Reproduce code: --------------- $a = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'a'); var_dump($a); var_dump(array_search('a', $a)); Expected result: ---------------- int(0) Actual result: -------------- int(1) -- Edit bug report at http://bugs.php.net/?id=46365&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46365&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46365&r=trysnapshot53 Try ...

  1. #1

    Default #46365 [NEW]: bug in function array_search

    From: spabox at hshhhhh dot name
    Operating system: winxp
    PHP version: 5.2.6
    PHP Bug Type: Arrays related
    Bug description: bug in function array_search

    Description:
    ------------
    bug in function array_search:
    when first element in array is zero, function return zero, but if null,
    false or sth else returning correct key.

    Reproduce code:
    ---------------
    $a = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'a');
    var_dump($a);
    var_dump(array_search('a', $a));

    Expected result:
    ----------------
    int(0)

    Actual result:
    --------------
    int(1)

    --
    Edit bug report at http://bugs.php.net/?id=46365&edit=1
    --
    Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46365&r=trysnapshot52
    Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46365&r=trysnapshot53
    Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46365&r=trysnapshot60
    Fixed in CVS: http://bugs.php.net/fix.php?id=46365&r=fixedcvs
    Fixed in release: http://bugs.php.net/fix.php?id=46365&r=alreadyfixed
    Need backtrace: http://bugs.php.net/fix.php?id=46365&r=needtrace
    Need Reproduce Script: http://bugs.php.net/fix.php?id=46365&r=needscript
    Try newer version: http://bugs.php.net/fix.php?id=46365&r=oldversion
    Not developer issue: http://bugs.php.net/fix.php?id=46365&r=support
    Expected behavior: http://bugs.php.net/fix.php?id=46365&r=notwrong
    Not enough info: http://bugs.php.net/fix.php?id=46365&r=notenoughinfo
    Submitted twice: http://bugs.php.net/fix.php?id=46365&r=submittedtwice
    register_globals: http://bugs.php.net/fix.php?id=46365&r=globals
    PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46365&r=php4
    Daylight Savings: http://bugs.php.net/fix.php?id=46365&r=dst
    IIS Stability: http://bugs.php.net/fix.php?id=46365&r=isapi
    Install GNU Sed: http://bugs.php.net/fix.php?id=46365&r=gnused
    Floating point limitations: http://bugs.php.net/fix.php?id=46365&r=float
    No Zend Extensions: http://bugs.php.net/fix.php?id=46365&r=nozend
    MySQL Configuration Error: http://bugs.php.net/fix.php?id=46365&r=mysqlcfg

    spabox Guest

  2. #2

    Default #46365 [Com]: bug in function array_search

    ID: 46365
    Comment by: spambox at hshhhhh dot name
    Reported By: spabox at hshhhhh dot name
    Status: Open
    Bug Type: Arrays related
    Operating System: winxp
    PHP Version: 5.2.6
    New Comment:

    in array_keys() bug too
    $a = array(0, 'a','a');
    var_dump(array_keys($a,'a'));


    #array(3) {
    # [0]=>
    # int(0)
    # [1]=>
    # int(1)
    # [2]=>
    # int(2)
    #}


    Previous Comments:
    ------------------------------------------------------------------------

    [2008-10-22 14:28:00] spabox at hshhhhh dot name

    Description:
    ------------
    bug in function array_search:
    when first element in array is zero, function return zero, but if null,
    false or sth else returning correct key.

    Reproduce code:
    ---------------
    $a = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'a');
    var_dump($a);
    var_dump(array_search('a', $a));

    Expected result:
    ----------------
    int(0)

    Actual result:
    --------------
    int(1)


    ------------------------------------------------------------------------


    --
    Edit this bug report at http://bugs.php.net/?id=46365&edit=1

    spambox Guest

  3. #3

    Default #46365 [Opn->Bgs]: bug in function array_search

    ID: 46365
    Updated by: net
    Reported By: spabox at hshhhhh dot name
    -Status: Open
    +Status: Bogus
    Bug Type: Arrays related
    Operating System: winxp
    PHP Version: 5.2.6
    New Comment:

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    http://www.php.net/manual/ and the instructions on how to report
    a bug at http://bugs.php.net/how-to-report.php

    Hello, read about the third parameter. (bool $strict)

    http://docs.php.net/array-search
    http://docs.php.net/array-keys


    Previous Comments:
    ------------------------------------------------------------------------

    [2008-10-22 14:32:44] spambox at hshhhhh dot name

    in array_keys() bug too
    $a = array(0, 'a','a');
    var_dump(array_keys($a,'a'));


    #array(3) {
    # [0]=>
    # int(0)
    # [1]=>
    # int(1)
    # [2]=>
    # int(2)
    #}

    ------------------------------------------------------------------------

    [2008-10-22 14:28:00] spabox at hshhhhh dot name

    Description:
    ------------
    bug in function array_search:
    when first element in array is zero, function return zero, but if null,
    false or sth else returning correct key.

    Reproduce code:
    ---------------
    $a = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'a');
    var_dump($a);
    var_dump(array_search('a', $a));

    Expected result:
    ----------------
    int(0)

    Actual result:
    --------------
    int(1)


    ------------------------------------------------------------------------


    --
    Edit this bug report at http://bugs.php.net/?id=46365&edit=1

    felipe@php.net Guest

Similar Threads

  1. #40247 [NEW]: array_merge + array_search gives wrong result
    By y1ngf4n at hotmail dot com in forum PHP Bugs
    Replies: 1
    Last Post: January 26th, 10:14 AM
  2. array_search, array_keys problem
    By Phil Powell in forum PHP Development
    Replies: 4
    Last Post: October 17th, 03:34 PM
  3. trouble with array_search
    By Catalin Trifu in forum PHP Development
    Replies: 3
    Last Post: August 30th, 05:15 PM
  4. #20681 [Com]: array_search(:object, :array) fails
    By hughjonesd at yahoo dot co dot uk in forum PHP Development
    Replies: 0
    Last Post: August 6th, 10:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139