Doc #65555 [NEW]: Example #1 seems to be incorrect.

From: Date: Mon, 26 Aug 2013 00:26:09 +0000
Subject: Doc #65555 [NEW]: Example #1 seems to be incorrect.
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10219@lists.php.net to get a copy of this message
From:             bsasser at sindtech dot net
Operating system: n/a
PHP version:      Irrelevant
Package:          Documentation problem
Bug Type:         Documentation Problem
Bug description:Example #1 seems to be incorrect.

Description:
------------
---
From manual page:
http://www.php.net/function.array-diff-key#refsect1-function.array-diff-key-examples
---
Example #1 *appears* incorrect (based on my own ignorance).

The description of 'array_diff_keys' is written in simple enough English I
*should* be able to see it the way you do (sorry, but I don't).  I must
have missed something.

Test script:
---------------
Your example:
$array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3,
'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7,
'cyan'   => 8);

var_dump(array_diff_key($array1, $array2));

Expected result:
----------------
I expected 'purple' to be included in the output because the function
"Compares the keys from array1 against the keys from array2 and returns the
difference."

Reading the Return Values portion of the function definition:
"Returns an array containing all the entries from array1 whose keys are not
present in any of the other arrays."

'purple' is included in $array1, but not $array2 - thus a difference.

'cyan' and 'yellow', though technically a 'difference', are not in
$array1
and therefore should not be returned based on the documentation.


Actual result:
--------------
Actual results are identical to those shown in your example #1.

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



Thread (3 messages)

« previous php.doc.bugs (#10219) next »