PHP 运行 artisan 命令时出现弃用问题

问题描述 投票:0回答:9

每当我运行 artisan 命令时,我都会遇到这个问题。

我正在使用 Valet 和 PHP 8.1。我已尝试更改 PHP 版本,但仍然遇到此问题。

当我跑步时:

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

退货:

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}
php composer-php octobercms
9个回答
16
投票

根据我的经验,这是由于尝试在 PHP 8.1 下运行 Laravel 7(或更早版本)造成的。我知道您说过您尝试更改 PHP 版本,但我会仔细检查您的更改是否确实生效。

对于 Laravel 7,切换回 PHP 8.0 解决了我的问题。

nb:Laravel 7 的

composer.json
错误地指定了
"php": "^7.2.5|^8.0",
,这意味着它can 在 PHP 8.1 下运行。


13
投票

就我而言,我有 Laravel 8.12,然后我收到了这个错误。 所以我在 Composer.json 中将

"laravel/framework": "^8.12",
更改为
"laravel/framework": "^8.75",
。然后我在终端上运行
composer update
。就这样!

*最后,当我运行时

php artisan --version
我的 laravel 版本是 8.83.1


6
投票

我运行了作曲家更新,它修复了问题


5
投票

当我将 php 版本从 7 更新到 8 时,我遇到了同样的问题。 我将“laravel/framework”更新为“^8.75”并运行作曲家更新。这对我有用。


1
投票

当我尝试在 php 8.1 上运行 Laravel 7.3 时,我遇到了同样的错误

对我来说,我的电脑上安装了 2 个版本的 php,

php-7.4 and php-8.1.

当我在终端上检查 php 版本时,使用

php --version
终端显示我正在使用 php 7.4

所以我以为 Laravel 使用的是 php 7.4,但事实并非如此。不知何故,Web 服务器(nginx)重定向到 php 8.1

要确定正在使用哪个 php 版本,请使用内置的 phpinfo() 方法。以下是一种方法

  • 从 Laravel 项目备份 index.php
  • 然后删除index.php文件中的所有内容

在index.php文件中添加以下内容

<?php
   phpinfo();
?>

然后尝试访问您的 Laravel 项目。 这将为您提供 php 信息页面,其中包含有关您的 Laravel 项目实际使用的 php 版本的信息。

当我在 macOS Big Sur 上使用自制程序时,我使用这些命令来停止 php8.1

brew services stop [email protected]
brew unlink [email protected]  

然后我开始了 php 7.4

brew services start [email protected]
brew link [email protected]

有关切换 php 版本的更多信息


0
投票

由于 laravel/php 版本,我遇到了同样的问题,我使用的是 laravel 6.X LTS 和 php 8.1,它们不兼容,您可以在此处查看https://laravel.com/docs/9.x/releases 所以你有两个选择,要么升级你的 laravel 要么降级你的 php,我的例子是我使用 Homestead 和 Vagrant,所以在你的 Homestead.yaml 的

sites
条目中你可以做类似的事情

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

或者您想要使用并运行的任何 php 版本

vagrant reload --provision


0
投票

我在使用 homestead 运行我的网络应用程序(使用 laravel 和 php7.3 )时遇到此错误。我花了很长时间才终于发现我得到的错误是在主机中运行 php8 导致的。

所以我也将主机上的php版本更改为7.3。

现在问题全部消失了。

我不知道为什么,但显然,主机中的 php 确实也会影响 homesteead 中的 php。

所以你需要确保homestead中的php版本与宿主机相同。


-4
投票

找到文件并添加方法头:

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

文档 & 示例


-5
投票

尝试检查composer.json和package.json的依赖关系,检查所有依赖关系是否都在正确的位置(对于生产->依赖关系而不是依赖关系-开发)

© www.soinside.com 2019 - 2024. All rights reserved.