4

Whenever I run an artisan command I am getting this issue.

I am using Valet and PHP 8.1. I have tried changing versions of PHP but I still get this issue.

When i run:

jakefeeley@Jakes-MBP marketing % php artisan plugin:install vojtasvoboda.twigextensions

Returns:

PHP Deprecated:  Return type of Illuminate\Container\Container::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 1231

Deprecated: Return type of Illuminate\Container\Container::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 1231
PHP Deprecated:  Return type of Illuminate\Container\Container::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 1242

Deprecated: Return type of October\Rain\Config\Repository::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/october/rain/src/Config/Repository.php on line 446
PHP Deprecated:  Return type of October\Rain\Config\Repository::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/october/rain/src/Config/Repository.php on line 458

Deprecated: Return type of October\Rain\Config\Repository::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/october/rain/src/Config/Repository.php on line 458
PHP Deprecated:  Return type of October\Rain\Config\Repository::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/october/rain/src/Config/Repository.php on line 469

Deprecated: Return type of October\Rain\Config\Repository::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/october/rain/src/Config/Repository.php on line 469
PHP Fatal error:  During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Support/Collection.php:1277
Stack trace:
#0 /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Support/Collection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8192, 'Return type of ...', '/Users/jakefeel...', 1277)
#1 /Users/jakefeeley/Sites/certhub/marketing/vendor/composer/ClassLoader.php(478): include('/Users/jakefeel...')
#2 /Users/jakefeeley/Sites/certhub/marketing/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile('/Users/jakefeel...')
#3 

In Collection.php line 11:
                                                                                                                                                                                                         
  During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset  
  ): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Support/Col  
  lection.php:1277                                                                                                                                                                                       
  Stack trace:                                                                                                                                                                                           
  #0 /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Support/Collection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8192, 'Return type of   
  ...', '/Users/jakefeel...', 1277)                                                                                                                                                                      
  #1 /Users/jakefeeley/Sites/certhub/marketing/vendor/composer/ClassLoader.php(478): include('/Users/jakefeel...')                                                                                       
  #2 /Users/jakefeeley/Sites/certhub/marketing/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile('/Users/jakefeel...')                                                                 
  #3 /Users/jakefeeley/Sites/certhub/marketing/vendor/october/rain/src/Support/Collection.php(11): Composer\Autoload\ClassLoader->loadClass('Illuminate\\Supp...')                                       
  #4 /Users/jakefeeley/Sites/certhub/marketing/vendor/composer/ClassLoader.php(478): include('/Users/jakefeel...')                                                                                       
  #5 /Users/jakefeeley/Sites/certhub/marketing/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile('/Users/jakefeel...')                                                                 
  #6 /Users/jakefeeley/Sites/certhub/marketing/vendor/october/rain/src/Support/helpers.php(269): Composer\Autoload\ClassLoader->loadClass('October\\Rain\\Su...')                                        
  #7 /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php(89): collect(Array)                                                                
  #8 /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config('aliases')                      
  #9 /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases()                    
  #10 /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(219): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap(Object(October\Rain  
  \Foundation\Application))                                                                                                                                                                              
  #11 /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(320): Illuminate\Foundation\Application->bootstrapWith(Array)                      
  #12 /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Foundation\Console\Kernel->bootstrap()                            
  #13 /Users/jakefeeley/Sites/certhub/marketing/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\Co  
  nsoleOutput))                                                                                                                                                                                          
  #14 {main}
Dharman
  • 26,923
  • 21
  • 73
  • 125
Jakef19
  • 91
  • 1
  • 1
  • 5
  • 3
    Does your dependencies also supports php 8.1? – Justinas Dec 06 '21 at 12:04
  • 1
    which build/version of OctoberCMS you are using? – Hardik Satasiya Dec 06 '21 at 12:34
  • @HardikSatasiya we are using 2.11.2 – Jakef19 Dec 06 '21 at 12:36
  • The latest OctoberCMS seems to be using Laravel 6.0 which does not officially support PHP 8.1 (or even PHP 8.0). If you installed it using composer you should have received errors notifying you of this – apokryfos Dec 06 '21 at 12:37
  • @apokryfos it supports 7.4 but i get the same errors – Jakef19 Dec 06 '21 at 12:38
  • 2
    according to your question you have PHP 8.1 which it does not support. That deprecation warning only exists in PHP 8.1 so if you tried different PHP versions and still got the same error then you didn't successfully switch PHP versions – apokryfos Dec 06 '21 at 12:39
  • can you please try checking it with PHP 8.0, as in my local I am using PHP 8.0.10 and plugin installed correctly, so it seems its PHP 8.1 may be – Hardik Satasiya Dec 06 '21 at 12:43

8 Answers8

7

In my experience this is due to attempting to run Laravel 7 (or earlier) under PHP 8.1. I know you said you tried changing PHP versions, but I would double-check that your changes definitely took effect.

For Laravel 7, switching back to PHP 8.0 fixed the issue for me.

nb: Laravel 7's composer.json incorrectly specifies "php": "^7.2.5|^8.0", which implies it can run under PHP 8.1.

jeff-h
  • 1,744
  • 1
  • 18
  • 28
3

I had the same problem when i update my php version from 7 to 8. I updated "laravel/framework" to "^8.75" and ran composer update. That works for me.

  • This helped me my laravel version was "laravel/framework": "^8.0", Changed it to "^8.75" Solved the issue – Lokesh Mar 21 '22 at 17:33
2

I ran composer update and it fixed things

Bojan S.
  • 95
  • 4
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31089963) – S.I. Feb 22 '22 at 10:09
1

In my case, i had Laravel 8.12 then i got this error. so i change "laravel/framework": "^8.12", to "laravel/framework": "^8.75", in Composer.json . then i ran composer update on terminal. there you go!

*at the end, when i ran php artisan --version my laravel version was 8.83.1

Ali Safaei
  • 41
  • 7
0

I was having same issues due to the laravel/php versions, I was using laravel 6.X LTS and php 8.1 which is not compatible as you can check here https://laravel.com/docs/9.x/releases so you have two choices either upgrade your laravel or downgrade your php, im my case I was using Homestead & Vagrant so in your sites entry of your Homestead.yaml you can do something like

sites:
    - map: your-site.local
      to: /home/vagrant/your-site/public
      php: "7.4"

Or any php version you want to use and run vagrant reload --provision

-2

I got the same error when I tried to run Laravel 7.3 on php 8.1

For me i had 2 versions of php installed php-7.4 and php-8.1.

When i checked on command line interface the version of php, using the command php --version i got php 7.4

So I thought php 7.4 was what laravel was using, But that was not the case. The web server (nginx) was redirecting to php 8.1

Tip for debuging:

copy index.php for backup (store it aside)

then remove everything on index.php add the following

<?php
   phpinfo();
?>

Try to access it. That will give you php information page that will contain the version of php your laravel installation is using.

As i was using brew on macos Big sur, i used these commands to stop php8.1

brew services stop php@8.1  

Starting php 7.4

brew services start php@7.4

For more info on switching php versions

Charden Daxicen
  • 350
  • 3
  • 8
-4

Find the file and add method header:

#[\ReturnTypeWillChange]
public function myFun() {
   [...]
}

Documentation & Example

Elikill58
  • 3,190
  • 22
  • 17
  • 38
-5

Try to check your dependences of composer.json and package.json, check if all dependences are in right place (for production->dependences not dependences-dev)