PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Text » Text_Statistics » Bug #4490

Divide by zero error

Details

Submitted2005-05-31 19:44 UTC
Frommjohnson at pitsco dot com
Assignedcweiske
StatusClosed
PackageText_Statistics
PHP VersionIrrelevant
OSAll
Roadmaps(Not assigned)

Comments

[2005-05-31 19:44 UTC] mjohnson at pitsco dot com

Description:
------------
Using version 1.0, I get a divide by zero error when passing a string that has no end-of-sentence punctuation. Also, an empty string elicits an extra divide by zero error.

A couple of approaches could be used to fix this. First, suppress the errors using the @ operator. Second, explicitly detect possible divide by zero conditions and either return some null value or force it to divide by one. Any solution would be viable. However, given the way the class works, either supressing the error or dividing by one is probably best.

Reproduce code:
---------------
$x = new Text_Statistics('');
$y = new Text_Statistics('Four score and seven years ago');

echo $x->flesch . "\n";
echo $y->flesch . "\n";

Expected result:
----------------
205.82
87.945

-or-

206.835
94.035

(either one is acceptable, since it's not a complete sentence)

Actual result:
--------------
Warning: Division by zero in /usr/share/php/Text/Statistics.orig.php on line 138

Warning: Division by zero in /usr/share/php/Text/Statistics.orig.php on line 139

Warning: Division by zero in /usr/share/php/Text/Statistics.orig.php on line 138
206.835
94.035