0

im trying to validate zend framework 2 barcodes but without success

the validation always returns false

    $bc128 = new Code128();
    $bc128->setText('TEST');
    $valid = new \Zend\Validator\Barcode('code128');
    if ($valid->isValid($bc128->getTextToDisplay())) {
        exit('valid');
    } else {
        exit('invalid');
    }

anyone knows whats going on?

user3070083
  • 13
  • 1
  • 4

1 Answers1

0

It certainly seems like a bug in Barcode validator's checksum logic. Validator trying to casting null (default) as boolean in few steps. (I don't know why)

You can workaround for now by passing a boolean false for useChecksum option like below:

$bc128 = new \Zend\Barcode\Object\Code128();
$bc128->setText('TEST');

$options = array(
    'adapter' => 'code128',
    'useChecksum' => false
    );

$valid = new \Zend\Validator\Barcode($options);

if ($valid->isValid($bc128->getTextToDisplay())) {
  exit('valid');
} else {
exit('invalid');
}

Related github issues link.

edigu
  • 9,878
  • 5
  • 57
  • 80