PHP Classes

_ean13CheckDigit() has bug.

Recommend this page to a friend!

      Barcode  >  All threads  >  _ean13CheckDigit() has bug.  >  (Un) Subscribe thread alerts  
Subject:_ean13CheckDigit() has bug.
Summary:two fix. one:_ean13CheckDigit() bug. two: notice message.
Messages:1
Author:r_koike
Date:2010-05-14 09:58:26
 

  1. _ean13CheckDigit() has bug.   Reply   Report abuse  
Picture of r_koike r_koike - 2010-05-14 09:58:26
ONE:
_ean13CheckDigit() has bug??

input:
$barnumber = '123456789012'; //12 charactors.
output:
incorrect: '0123456789012'; //add no $checksumDigit, and '0' padding.
correct: '1234567890128'; //inputs plus $checksumDigit='8' .

patch:
========================================================
1559c1559
< if(strlen($barnumber) <= 11 )
---
> if(strlen($barnumber) <= 12 )
1561c1561
< $barnumber = str_pad($barnumber, 12, "0", STR_PAD_LEFT);
---
> $barnumber = str_pad($barnumber, 13, "0", STR_PAD_LEFT);
1579,1591c1579,1583
< if(strlen($barnumber) <= 12 )
< {
< if( $csumTotal % 10 == 0 )
< $checksumDigit = '';
< else
< $checksumDigit = 10 - ($csumTotal % 10);
< $barnumber .= $checksumDigit;
< }
< if(strlen($barnumber) <= 12 )
< {
< $barnumber = str_pad($barnumber, 13, "0", STR_PAD_LEFT);
< }
< return $barnumber;
---
> if( $csumTotal % 10 == 0 )
> $checksumDigit = '';
> else
> $checksumDigit = 10 - ($csumTotal % 10);
> return $barnumber.$checksumDigit;
========================================================

TWO:

Notice: Undefined variable: space in /path/to/barcode.inc.php on line 1669
========================================================
1669c1661
< if (empty($space))
---
> if (!$space)
========================================================