php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79402 Description fix suggestion
Submitted: 2020-03-22 00:40 UTC Modified: 2021-12-14 10:29 UTC
From: simongcc at gmail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: simongcc at gmail dot com
New email:
PHP Version: OS:

 

 [2020-03-22 00:40 UTC] simongcc at gmail dot com
Description:
------------
---
From manual page: https://php.net/language.operators.array
---

It is only a problem in description.

In the docs, it states that $a + $b is Union and it is Union of $a and $b.
But it is not completely reflecting the characteristic of the Union in PHP.
Since strictly speaking, an Union should be mutually inclusive of different things.

In PHP, it is only an union of key regardless of value.
So it should be written as

Union of the key in $a and $b and based on $a or vice versa if it is $b + $a. (Because when there is/are key(s) exist(s) in the first variable, the same key(s) in the second variable will be ignored)


Test script:
---------------
$a = array('something' => 'interesting', 2);
$b = array('another' => 'interesting thing', 0 => 3);
$c = $a + $b;
$d = $b + $a;

print_r($c);
print_r($d);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-22 13:37 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-03-22 13:37 UTC] cmb@php.net
Isn't that already sufficiently explained:

| The + operator returns the right-hand array appended to the
| left-hand array; for keys that exist in both arrays, the elements
| from the left-hand array will be used, and the matching elements
| from the right-hand array will be ignored.
 [2020-04-05 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2021-12-14 01:29 UTC] simongcc at gmail dot com
The description describe correctly, however, using "union of" in the example have a potential to mislead some "fast glance" people. But I agree, it is a minor problem instead of critical.
 [2021-12-14 10:29 UTC] cmb@php.net
-Status: No Feedback +Status: Open -Package: Documentation problem +Package: *General Issues -Assigned To: cmb +Assigned To:
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC