【发布时间】:2020-09-21 20:57:31
【问题描述】:
我正在尝试在 Laravel 5.5 中渲染电子邮件,但无论我做什么,渲染时都会出现以下错误:
ErrorException (E_NOTICE) Trying to access array offset on value of type null
发生在 \vendor\egulias\email-validator\EmailValidator\Parser\Parser.php
我正在运行 php 7.4,我相信错误不会发生在 php 7.3 上。
web.php:
Route::get('scratch', function(){
$mail = new Test();
return $mail->render();
});
Test.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class Test extends Mailable
{
use Queueable, SerializesModels;
public $subscription;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.test');
}
}
test.blade.php
Hello from world
我认为这一定是 Laravel 5.5 和 PHP 7.4 的问题。我可以更改我的版本,但如果可能的话,我想避免这种情况。升级 Laravel 不适用于此应用程序。
编辑
vendor\egulias\email-validator\EmailValidator\Parser\Parser.php 这一行失败
protected function escaped()
{
$previous = $this->lexer->getPrevious();
if ($previous['type'] === EmailLexer::S_BACKSLASH // here
&&
$this->lexer->token['type'] !== EmailLexer::GENERIC
) {
return true;
}
return false;
}
【问题讨论】:
-
你能通过堆栈跟踪找出数组访问发生在哪里吗?它应该是一个错误,所以 PHP 7.4 是正确的,但在过去它会返回
null(不是错误) -
@lagbox 已更新以显示失败位置。
-
你尝试过什么调试问题?
-
除非您通过您的代码可以调整最终从
$this->lexer->getPrevious()返回的内容,否则您将无法使用它,除非有较新的版本,或者您分叉此包并调整该代码以检查对于null -
github.com/egulias/EmailValidator/issues/234 上已经有一个错误报告,并且从 v2.1.16 开始提供修复 - 您使用的是哪一个?