php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62512 [FR] Error about array operators documentation
Submitted: 2012-07-08 20:38 UTC Modified: 2012-08-02 09:46 UTC
From: php at maerdo dot com Assigned: yannick (profile)
Status: Closed Package: Translation problem
PHP Version: 5.4.4 OS: n/a
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at maerdo dot com
New email:
PHP Version: OS:

 

 [2012-07-08 20:38 UTC] php at maerdo dot com
Description:
------------
This page inform that the addition of two arrays add datas of left array to datas of the right array :

" L'opérateur + retourne le tableau de droite auquel sont ajoutés les éléments du tableau de gauche."

After test it, i note the behavior is opposite.
The addition of these arrays result in the addition of datas of the right array to datas of the left array.


<?php

$array1=['a'=>1,'b'=>2];
$array2=['a'=>'A','B','C'];

var_dump($array1+$array2);

// output
array(4) { ["a"]=> int(1) ["b"]=> int(2) [0]=> string(1) "B" [1]=> string(1) "C" }
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-09 09:58 UTC] php at maerdo dot com
URL : http://www.php.net/manual/fr/language.operators.array.php
 [2012-07-20 05:54 UTC] aharvey@php.net
-Package: Documentation problem +Package: Translation problem
 [2012-07-24 05:31 UTC] googleguy@php.net
The documentation appears to be correct from the English docs. I can't speak for the French 
translation, or its accuracy. However, I will note that the addition operator is left-associative (as 
PHP operators take on precedence and associativity rules mostly from C).

So to say that the expression ($arr1 + $arr2) yields left association, is by definition correct. 
Because $arr1 will be appending all elements in $arr2, that belong to keys which do not exist in 
$arr1.

In your example, the elements of $array1:
    (
     'a' => 1,
     'b' => 2
    )
show up first in the resulting array. Any keys found in $array2 that exist in $array1 (in this case 
'a'), will simply be ignored and the values of keys found in the second operand, which do not exist 
in the first operand, will be appended in the yielding expression.

This can be a bit confusing when phrased as "left is added to right" or "right is added to left". So 
instead it's best to explain this from the perspective of an operator as opposed to the perspective 
of the operands (in a technical documentation).

A left associative operator tells us that the operands are grouped to the left in the absence of parenthesis. This means when we spot the operator we need to group its right-hand operand with its 
left-hand operand when applying the operator.

I hope this might help to disambiguate the technical wording found in the French translation.
 [2012-07-29 07:16 UTC] yannick@php.net
-Summary: Error about array operators documentation +Summary: [FR] Error about array operators documentation
 [2012-08-02 09:45 UTC] yannick@php.net
Automatic comment from SVN on behalf of yannick
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=326941
Log: Fix bug #62512
 [2012-08-02 09:46 UTC] yannick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: yannick
 [2012-08-02 09:46 UTC] yannick@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

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


 [2020-12-30 12:49 UTC] nikic@php.net
Automatic comment on behalf of yannick
Revision: http://git.php.net/?p=doc/fr.git;a=commit;h=70b42ebb86ed2e32314c4bb84867d8b2511d10f0
Log: Fix bug #62512
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 20:01:29 2024 UTC