skip to Main Content

i used to use my Laravel Project with PhP 5.6 and i’m using barcode Gnerator for my project some where and to do this i use this package .

laravel/laravel barcode_blog

now i upgraded my PhP To 7.4 (note: didn’t upgrade my laravel yet).
everything is working fine just when i search for a spasific barcode i got this error :

ErrorException in BarcodeGenerator.php line 293: 
Array and string offset access syntax with curly braces is deprecated (View:.../.../..)

now this is the code :

<tr>
    <td width="19%">serial NUM</td>
    <td style="width: 1%">:</td>
    <td colspan="2">
     @if (!empty($INSTANCE))
       <?php $generator = new PicqerBarcodeBarcodeGeneratorHTML(); ?>
       {!! $generator->getBarcode($INSTANCE->barcode, $generator::TYPE_CODE_128) !!}
    @endif
    </td>
   </tr>

And I know the problem is with $generator = new PicqerBarcodeBarcodeGeneratorHTML(); this line when i delete it my code is working fine but i need it in the code how to use it in php 7.4 i belive it get changed

2

Answers


  1. Update your composer or to be exact, update picqer/php-barcode-generator version and it will work fine. To update composer, just type
    ‘composer update’ on the terminal within your project files and it should work.

    Login or Signup to reply.
  2. Installing packages via composer installs packages based on your environment (PHP version).

    This means that if you upgrade your PHP version you have to update your installed packages as well via composer update as mentioned before.

    But your versions in composer.json might be locked to some specific versions, in which case you will have to change that as well.
    Composer update will leave you an error message then.

    What I usual do is:

    • Try running composer update
    • If it fails or syntax errors still occur in the project I look up the package on packagist.org to see what major versions require what PHP versions
      Screenshot from Packagist.org regarding versions
    • Packages on packagist usually adher to the semantic versioning (semver.org) which means that you would typically have to find a new major version (the first number in versioning) that can run on your PHP version.

    In your example you should be able to change the picqer/php-barcode-generator package to use version 2.1 or higher.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search