Doc #75027 [NEW]: Document correction
| From: | vivek_buzruk at yahoo dot com | Date: | Thu, 03 Aug 2017 05:41:12 +0000 |
| Subject: | Doc #75027 [NEW]: Document correction | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-14878@lists.php.net to get a copy of this message | ||
From: vivek_buzruk at yahoo dot com
Operating system: windows
PHP version: 7.1.7
Package: PHP Language Specification
Bug Type: Documentation Problem
Bug description:Document correction
Description:
------------
---
From manual page: http://www.php.net/language.operators.comparison
---
I feel array comparison "standard_array_compare" mentioned in this page
need correction.
If "!array_key_exists($key, $op2)" returns "null", then "count($op1) <
count($op2)" and "count($op1) > count($op2)" should both return "null".
If the length of arrays do not match then either of them contain atleast
1 key different / additional than other. Is that right?
One more observation and comment => comparison is non-type based for Key
values, but larger question is should "null" be returned considering
difference Key values? Do we consider that both arrays are of different
types when "Key" values do not match?
Anyway, depends on the particular need and interpretation, but we can
also say that function returns "null" as 2 arrays are non-comparable
when Keys do not match.
So, in my view array comparison function should be =>
==================
<?php
// Arrays are compared like this with standard comparison operators
function standard_array_compare($op1, $op2)
{
if (count($op1) < count($op2) || count($op1) > count($op2)) {
return null; // uncomparable
}
foreach ($op1 as $key => $val) {
if (!array_key_exists($key, $op2)) {
return null; // uncomparable
} elseif ($val < $op2[$key]) {
return -1;
} elseif ($val > $op2[$key]) {
return 1;
}
}
return 0; // $op1 == $op2
}
?>
Test script:
---------------
Same as example above
--
Edit bug report at https://bugs.php.net/bug.php?id=75027&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75027&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75027&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75027&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75027&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75027&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75027&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75027&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75027&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75027&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75027&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75027&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75027&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75027&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75027&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75027&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75027&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75027&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75027&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75027&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75027&r=mysqlcfg