Professional Web Applications Themes

#25494 [Opn->Csd]: array_merge allowing "false" as argument (silent when non-array is passed) - PHP Development

ID: 25494 Updated by: [email]jayphp.net[/email] Reported By: enygma at phpdeveloper dot org -Status: Open +Status: Closed Bug Type: Arrays related Operating System: Red Hat Linux PHP Version: 4.3.2 New Comment: This bug has been fixed in CVS. In case this was a PHP problem, snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at [url]http://snaps.php.net/[/url]. In case this was a doentation problem, the fix will show up soon at [url]http://www.php.net/manual/[/url]. In case this was a PHP.net website problem, the change will show up on the PHP.net site ...

  1. #1

    Default #25494 [Opn->Csd]: array_merge allowing "false" as argument (silent when non-array is passed)

    ID: 25494
    Updated by: [email]jayphp.net[/email]
    Reported By: enygma at phpdeveloper dot org
    -Status: Open
    +Status: Closed
    Bug Type: Arrays related
    Operating System: Red Hat Linux
    PHP Version: 4.3.2
    New Comment:

    This bug has been fixed in CVS.

    In case this was a PHP problem, snapshots of the sources are packaged
    every three hours; this change will be in the next snapshot. You can
    grab the snapshot at [url]http://snaps.php.net/[/url].

    In case this was a doentation problem, the fix will show up soon at
    [url]http://www.php.net/manual/[/url].

    In case this was a PHP.net website problem, the change will show
    up on the PHP.net site and on the mirror sites in short time.

    Thank you for the report, and for helping us make PHP better.

    array_merge() throws E_NOTICEs now in 4.3.x and will throw
    a warning and fail in 5 for non-array arguments.

    J


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

    [2003-09-11 12:11:09] [email]andreyphp.net[/email]

    Jay, it's an undoented feature. If it is not doented and obscure
    it's developer's risk to use it. So, I think this is a bug and a check
    for the input parameter should be performed. A warning throwed in the
    same way as array_intersect() does will be the consistent way.
    Opening again :)

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

    [2003-09-11 11:50:39] enygma at phpdeveloper dot org

    it still seems silly to me that a string passed into an array function
    was taken without so much as a warning. even more strange that it was
    suddenly treated as an array and merged into the other valid array.

    maybe a warning would be enough to deter this in the future?

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

    [2003-09-11 11:42:26] [email]jayphp.net[/email]

    If you use var_dump() in place of print_r(), you'd see
    that it's not a mysterious value, it's 'false'. The
    boolean value is being converted to an array index in
    array_merge(). (Any value would produce similar results --
    $array1=4; would produce an array value of
    $last_array[0]==4.)

    array_intersect() does a type check before it does
    anything, which is why the warning comes up.

    While it seems inconsistent, I can't see this being
    changed because it would affect BC (albeit BC on a
    somewhat obscure, undoented feature). Somebody correct
    me here if I'm wrong. So I'm bogusing it for now.

    J

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

    [2003-09-11 11:42:19] [email]andreyphp.net[/email]

    1. Please use var_dump() instead of print_r()
    2. The value in the merged array is (bool) false

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

    [2003-09-11 10:59:27] enygma at phpdeveloper dot org

    array_merge_recursive() shows the same behavior
    array_intersect(), however, doesn't and gives a correct warning message

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

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    [url]http://bugs.php.net/25494[/url]

    --
    Edit this bug report at [url]http://bugs.php.net/?id=25494&edit=1[/url]
    jay@php.net Guest

  2. #2

    Default #25494 [Opn->Csd]: array_merge allowing "false" as argument (silent when non-array is passed)

    ID: 25494
    Updated by: [email]sniperphp.net[/email]
    Reported By: enygma at phpdeveloper dot org
    -Status: Open
    +Status: Closed
    Bug Type: Arrays related
    Operating System: Any
    PHP Version: 4.3.2
    New Comment:

    Throwing an E_NOTICE error is not breaking anything.



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

    [2003-09-18 05:56:38] [email]etphp.net[/email]

    This `fix' is inconsistent with array_splice, which allows you to add
    non-array arguments. (This is also doented.)
    Also, this `fix' breaks BC. Is this really needed?
    I'd rather have those functions convert non-array arguments into arrays
    and then perform their operations like array_splice() does.
    This has to be doented of course.

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

    [2003-09-11 13:57:55] [email]jayphp.net[/email]

    This bug has been fixed in CVS.

    In case this was a PHP problem, snapshots of the sources are packaged
    every three hours; this change will be in the next snapshot. You can
    grab the snapshot at [url]http://snaps.php.net/[/url].

    In case this was a doentation problem, the fix will show up soon at
    [url]http://www.php.net/manual/[/url].

    In case this was a PHP.net website problem, the change will show
    up on the PHP.net site and on the mirror sites in short time.

    Thank you for the report, and for helping us make PHP better.

    array_merge() throws E_NOTICEs now in 4.3.x and will throw
    a warning and fail in 5 for non-array arguments.

    J

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

    [2003-09-11 12:11:09] [email]andreyphp.net[/email]

    Jay, it's an undoented feature. If it is not doented and obscure
    it's developer's risk to use it. So, I think this is a bug and a check
    for the input parameter should be performed. A warning throwed in the
    same way as array_intersect() does will be the consistent way.
    Opening again :)

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

    [2003-09-11 11:50:39] enygma at phpdeveloper dot org

    it still seems silly to me that a string passed into an array function
    was taken without so much as a warning. even more strange that it was
    suddenly treated as an array and merged into the other valid array.

    maybe a warning would be enough to deter this in the future?

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

    [2003-09-11 11:42:26] [email]jayphp.net[/email]

    If you use var_dump() in place of print_r(), you'd see
    that it's not a mysterious value, it's 'false'. The
    boolean value is being converted to an array index in
    array_merge(). (Any value would produce similar results --
    $array1=4; would produce an array value of
    $last_array[0]==4.)

    array_intersect() does a type check before it does
    anything, which is why the warning comes up.

    While it seems inconsistent, I can't see this being
    changed because it would affect BC (albeit BC on a
    somewhat obscure, undoented feature). Somebody correct
    me here if I'm wrong. So I'm bogusing it for now.

    J

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

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    [url]http://bugs.php.net/25494[/url]

    --
    Edit this bug report at [url]http://bugs.php.net/?id=25494&edit=1[/url]
    sniper@php.net Guest

Similar Threads

  1. Replies: 0
    Last Post: October 8th, 01:03 AM
  2. Replies: 0
    Last Post: October 6th, 05:51 PM
  3. Replies: 0
    Last Post: September 23rd, 05:42 PM
  4. Replies: 0
    Last Post: September 23rd, 04:58 PM
  5. Replies: 0
    Last Post: September 19th, 02:44 PM

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