Version 5 introduced full support for mixed mode QR Codes by adding several segments via the methods QRCode::addByteSegment() [...] and then call QRCode::render() without the $data parameter.
However, it is possible to add several data segments and call the render method with data, which then adds another segment to the existing ones.
Steps to reproduce the behavior
invoke new QRCode instance
add one or more data segments
call QRCode::render() with the $data parameter set to a valid value
examine the rendered QR Code by scanning with a mobile device or using the built-in reader
Code sample (if applicable)
$qrcode = (new QRCode($options))
->addNumericSegment('1312')
->addAlphaNumSegment('ACAB')
;
$out = $qrcode->render('1312'); // rendered QR Code content: 1312ACAB1312
Expected behavior
The logical expectation is that the rendered QR Code would only contain the data given via the parameter or via the add*Segment() methods - this could be easily ensured by calling QRCode::clearSegments() after the $data check in line 79 in the code excerpt below.
However, I could see a legitimate reason for leaving the current behaivor as it is: adding an ECI designator before calling QRCode::render('<binary data>'), which is equivalent to calling QRCode::addEciSegment(<encoding>, '<binary data>') and then call the renderer without data.
$qrcode = (new QRCode($options))->addEciDesignator(ECICharset::WINDOWS_1251_CYRILLIC);
$out = $qrcode->render('<encoded binary data>'); // rendered QR Code content: <ECI header><encoded binary data>
I'm not exactly sure how to proceed with this (fix it or just document the behavior), so I'm leaving it here for a while to gather community opinions (maybe!?).
Describe the bug or unexpected behaviour
Version 5 introduced full support for mixed mode QR Codes by adding several segments via the methods
QRCode::addByteSegment()
[...] and then callQRCode::render()
without the$data
parameter. However, it is possible to add several data segments and call the render method with data, which then adds another segment to the existing ones.Steps to reproduce the behavior
QRCode
instanceQRCode::render()
with the$data
parameter set to a valid valueCode sample (if applicable)
Expected behavior
The logical expectation is that the rendered QR Code would only contain the data given via the parameter or via the
add*Segment()
methods - this could be easily ensured by callingQRCode::clearSegments()
after the$data
check in line 79 in the code excerpt below.https://github.com/chillerlan/php-qrcode/blob/87a833e797b88ea70047bf503cd1bbf67edb58a8/src/QRCode.php#L74-L92
However, I could see a legitimate reason for leaving the current behaivor as it is: adding an ECI designator before calling
QRCode::render('<binary data>')
, which is equivalent to callingQRCode::addEciSegment(<encoding>, '<binary data>')
and then call the renderer without data.I'm not exactly sure how to proceed with this (fix it or just document the behavior), so I'm leaving it here for a while to gather community opinions (maybe!?).
Environment:
v5.x