11

当我尝试向数据库提交发布请求时遇到问题。有趣的是,该错误仅在我使用 PHP 7.4.2 版本时发生。在 PHP 7.3.9 版本中一切正常。我正在使用 Laravel 6.17。

Laravel 什么时候解决这个问题?

这是我的堆栈跟踪,当错误出现时。

Trying to access array offset on value of type int   
in CreateCourseController.php line 176
at HandleExceptions->handleError()
in CreateCourseController.php line 176
at CreateCourseController->createDates()
in CreateCourseController.php line 101
at CreateCourseController->createCourse()
at call_user_func_array()
in Controller.php line 54
at Controller->callAction()
in ControllerDispatcher.php line 45
at ControllerDispatcher->dispatch()
in Route.php line 219
at Route->runController()
in Route.php line 176
at Route->run()
in Router.php line 681
at Router->Illuminate\Routing\{closure}()
in Pipeline.php line 130
at Pipeline->Illuminate\Pipeline\{closure}()
in SubstituteBindings.php line 41
at SubstituteBindings->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in VerifyCsrfToken.php line 76
at VerifyCsrfToken->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in StartSession.php line 56
at StartSession->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in EncryptCookies.php line 66
at EncryptCookies->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in Pipeline.php line 105
at Pipeline->then()
in Router.php line 683
at Router->runRouteWithinStack()
in Router.php line 658
at Router->runRoute()
in Router.php line 624
at Router->dispatchToRoute()
in Router.php line 613
at Router->dispatch()
in Kernel.php line 170
at Kernel->Illuminate\Foundation\Http\{closure}()
in Pipeline.php line 130
at Pipeline->Illuminate\Pipeline\{closure}()
in TransformsRequest.php line 21
at TransformsRequest->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in TransformsRequest.php line 21
at TransformsRequest->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in ValidatePostSize.php line 27
at ValidatePostSize->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in CheckForMaintenanceMode.php line 63
at CheckForMaintenanceMode->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in TrustProxies.php line 57
at TrustProxies->handle()
in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}()
in Pipeline.php line 105
at Pipeline->then()
in Kernel.php line 145
at Kernel->sendRequestThroughRouter()
in Kernel.php line 110
at Kernel->handle()
in index.php line 55

问候

4

5 回答 5

6

Laravel 存储库中已经列出了类似的问题

根据PHP-Doc,这是一个向后不兼容的变化PHP 7.4

非数组的数组式访问

bool, int, floator resourceas an array(例如$null["key"]) 现在将生成通知。

于 2020-02-26T11:39:14.247 回答
5

composer update为我的案例工作:

我有一个Laravel 5.6应用程序,带有Php 7.1.

此外,我必须更改laracasts/generators为fromcomposer.json才能开始,例如:^1.0dev-mastercomposer update

"laracasts/generators": "^1.0"

开始在一些旧项目上解决此问题,问题发生php artisan migratecomposer install.

https://github.com/spatie/laravel-permission/issues/1370#issuecomment-676556816

于 2020-08-19T17:15:21.933 回答
2

这是关于PHP版本的。在 php 7.4rc 中,通过键访问数组,有时会导致错误。这个错误很少发生在 php 7.2 上。检查数组是否有成员只需使用empty($array)函数

于 2020-05-17T14:06:23.787 回答
2

您可能正在尝试访问非数组类型(可能是对象类型)。

我也遇到过同样的情况,但它的不同之处在于一个片段访问一个对象,而另一个片段访问一个有效的数组类型。

下面的代码产生错误Trying to access array offset of value of type int

$mymodel = MyModel::where(array(
            'someid' => $somevar
        ))->get();
foreach($mymodel as $data){
     //etc
}

我尝试将其更新为:

$mymodel = MyModel::where(array(
            'someid' => $somevar
        ))->get()->toArray();
foreach($mymodel as $data){
     //etc
}

但是,您发布代码会非常有帮助,以便我们进一步检查。

于 2020-07-15T15:38:01.620 回答
1

如果您使用 php 7.4 并且使用过的软件包已开发为 php <7.4,则会显示此错误。

将您的 php 版本更改为旧版本(例如,php 7.4 到 7.3)。

我使用了 php 7.4 FPM,但 mPDF 的固定版本适用于 php 7.3 及以下版本。在我将 php 版本更改为 7.3 并且它工作后,我发现了这个错误。

我也用过宅基地。查看我的 php 配置:

sites:
    - map: myapp.test
      to: /home/vagrant/code/myapp/public
      php: "7.3"

vagrant reload --provision在 CLI 中运行。此命令应用新配置。

于 2021-03-15T07:26:24.963 回答