Doc #63204 [Opn->Csd]: Unreadable example code, replacement enclosed

From: Date: Wed, 16 Jan 2013 22:59:08 +0000
Subject: Doc #63204 [Opn->Csd]: Unreadable example code, replacement enclosed
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9436@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63204&edit=1 ID: 63204 Updated by: googleguy@php.net Reported by: henry at henrysmith dot org Summary: Unreadable example code, replacement enclosed -Status: Open +Status: Closed Type: Documentation Problem Package: Documentation problem Operating System: N/A PHP Version: Irrelevant -Assigned To: +Assigned To: googleguy Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2013-01-16 22:58:13] googleguy@php.net Automatic comment from SVN on behalf of googleguy Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=329171 Log: Provided some more practical examples for array_udiff. Also fixes bug #63204. ------------------------------------------------------------------------ [2012-10-03 07:45:28] henry at henrysmith dot org Description: ------------ --- From manual page: http://www.php.net/function.array-udiff#refsect1- function.array- udiff-examples --- This is my case for replacing this example code: It uses a class when there is no need to, and then to make matters worse the class is named "cr" with no explanation as to what this means. All-lower-case class names go against prevailing PHP code standards too. The class only has one single attribute, and it's poorly-named. A name like "priv_member" tells us nothing that the bare syntax doesn't already tell us. The class' constructor is in the old "repeat the class name" style, and accepts another badly-named parameter: $val. Again, every variable is a "value" so this tells us nothing about what's going on. The static comparator method is called "comp_func_cr". Presumably this means "Compute function CR". Again, we know it's a function from the syntax, we know it'll compute something because that's what functions *do*, and we know it's in the "cr" class because we're looking at it right now in the "cr" class. Inside the comparator, usage of whitespace is so randomly varied as to be confusing to the reader, and thanks to all the long "priv_member" attributes it's difficult to see what's actually being compared and returned. The instantiation code that creates arrays of "cr" objects is arranged into over-long lines, and although it defines keys for the array elements, it is not arranged into a sensible visual order from 0 to 2. A proposed replacement is enclosed as the "test script". Its output is enclosed as the "actual result". The code executes the same and produces the same output as the existing example, but without any of the issues mentioned above. Test script: --------------- <?php $one = array( '0' => 23, '0.1' => 9, '0.5' => 12, '1' => 4, '2' => -15, ); $two = array( '0' => 3, '0.2' => 9, '0.5' => 22, '1' => 4, '2' => -15, ); $result = array_udiff($one, $two, function($a, $b) { if ($a === $b) { return 0; } elseif ($a > $b) { return 1; } else { return -1; } }); print_r($result); Actual result: -------------- Array ( [0] => 23 [0.5] => 12 ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63204&edit=1

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