endroid / qr-code

QR Code Generator
https://endroid.nl
MIT License
4.46k stars 727 forks source link

getting error while working with pngWriter #405

Closed deepakchandrawanshi1063 closed 1 year ago

deepakchandrawanshi1063 commented 1 year ago

Error :

An uncaught Exception was encountered

<p>Type: ParseError</p>
<p>Message: syntax error, unexpected '|', expecting variable (T_VARIABLE)</p>
<p>Filename: /opt/lampp/htdocs/sis-backend/vendor/endroid/qr-code/src/Writer/PngWriter.php</p>
<p>Line Number: 18</p>

Code :

use Endroid\QrCode\Color\Color; use Endroid\QrCode\Encoding\Encoding; use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow; use Endroid\QrCode\QrCode; use Endroid\QrCode\Label\Label; use Endroid\QrCode\Logo\Logo; use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin; use Endroid\QrCode\Writer\PngWriter; use Endroid\QrCode\Writer\ValidationException;

`public function getQR($data){

    $writer = new PngWriter();
    $input=......;
    $encrypted = $this->encryptIt( $input );
    $decrypted = $this->decryptIt( base64_decode(base64_encode($encrypted) ));
    $schoolInfo = .....;
    $qrCode = QrCode::create(base_url('index.php/extrinsic/getQRValidity/'.base64_encode($encrypted)))
                    ->setEncoding(new Encoding('UTF-8'))
                    ->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
                    ->setSize(500)
                    ->setMargin(10)
                    ->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
                    ->setForegroundColor(new Color(0, 0, 0))
                    ->setBackgroundColor(new Color(255, 255, 255));

    $logo = Logo::create($schoolInfo->si_school_logo)
                ->setResizeToWidth(140);

    // Create generic label
    $label = Label::create($schoolInfo->si_school_name)
                ->setTextColor(new Color(255, 0, 0));

    $result = $writer->write($qrCode, $logo, $label);
    header('Content-Type: '.$result->getMimeType());

    return $result->getString();
}`
endroid commented 1 year ago

Hi @deepakchandrawanshi1063 your code breaks on union types, which are introduced in PHP 8.0. You should use at least PHP 8.0 when using this library. Older PHP versions are not supported. Good luck!

deepakchandrawanshi1063 commented 1 year ago

but i am already using php 8.2.4 , composer 2.5.5 and "endroid/qr-code": "^4.8" .

endroid commented 1 year ago

Hi @deepakchandrawanshi1063 sorry but I can not find another reason for this issue, as the pipe / union is supported since PHP 8.0 and my tests agains all PHP versions succeed (see https://github.com/endroid/qr-code/actions). In other words: from this end I can not do anything to debug or fix the issue in your environment.

You could try to output the PHP version from your script using echo PHP_VERSION from the same script to make 100% what PHP version it is running under. Or if you can provide an MR containing a failing test case I can look into it. Good luck again :)