php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53170 Cannot substract Arrays
Submitted: 2010-10-26 17:37 UTC Modified: 2021-06-08 14:33 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: gmblar+php at gmail dot com Assigned: cmb (profile)
Status: Wont fix Package: Arrays related
PHP Version: 5.3.3 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-10-26 17:37 UTC] gmblar+php at gmail dot com
Description:
------------
Add is supported but substract Arrays not

Test script:
---------------
<?php

$foo = array('a' => 1, 'b' => 2);
$bar = array('c' => 3, 'd' => 4);

$foobar = $foo + $bar;
print_r($foobar);

$foo = $foobar - $bar;
print_r($foo);

?>

Expected result:
----------------
Array
(
    [a] => 1
    [b] => 2
    [c] => 3
    [d] => 4
)


Array
(
    [a] => 1
    [b] => 2
)


Actual result:
--------------
Array
(
    [a] => 1
    [b] => 2
    [c] => 3
    [d] => 4
)

Fatal error: Unsupported operand types in array.php on line 9

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-26 20:16 UTC] gmblar+php at gmail dot com
Expect same behavior as array_diff() http://de.php.net/manual/en/function.array-
diff.php
 [2021-06-08 14:33 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-06-08 14:33 UTC] cmb@php.net
Well, some may want - to behave like array_diff(), others as
array_diff_assoc(), and others as array_diff_key().  I'm not even
sure which one I'd prefer, but I'm fine with being explicit, and
rather avoid thinking about it.

If you stll feel this would be a valuable addition to PHP, please
pursue the RFC process[1].

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC