4

I am trying to render an email in Laravel 5.5, but no matter what I do, I get the following error on render: ErrorException (E_NOTICE) Trying to access array offset on value of type null

happens in \vendor\egulias\email-validator\EmailValidator\Parser\Parser.php

I am running php 7.4 and I believe the error does NOT happen on 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

I'm thinking this has to be an issue with Laravel 5.5 and PHP 7.4. I can change my version but I'd like to avoid that if possible. Upgrading Laravel won't work for this application.


edit

It's failing on this line in 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;
    }
mkrell
  • 183
  • 2
  • 10
  • 1
    can you look through the stacktrace to find out where the array access is happening? it should be an error so PHP 7.4 got that right but in the past it would return `null` (not an error) – lagbox Sep 21 '20 at 21:01
  • @lagbox updated to show the fail location. – mkrell Sep 22 '20 at 12:07
  • What have you tried to debug the problem? – Nico Haase Sep 22 '20 at 12:11
  • unless you through your code can adjust what ends up being returned from `$this->lexer->getPrevious()` you won't be able to use this unless there is a newer version or you fork this package and adjust that code to check for the `null` – lagbox Sep 22 '20 at 12:12
  • 1
    There is already a bug report on https://github.com/egulias/EmailValidator/issues/234, and a fix is available since v2.1.16 - which one are you using? – Nico Haase Sep 22 '20 at 12:13
  • v2.1.7 lol. Composer update fixes it. Thx! – mkrell Sep 22 '20 at 12:55

2 Answers2

5

Issue is that egulias/email-validator 2.1.7 has php 7.4 issues. Simple composer update fixed it.

mkrell
  • 183
  • 2
  • 10
2

In my case i have just updated code In line 147 of this file vendor\egulias\email-validator\EmailValidator\Parser\Parser.php

Previous code was

if ($previous['type'] === EmailLexer::S_BACKSLASH

New code

if (isset($previous['type']) && $previous['type'] === EmailLexer::S_BACKSLASH

and my problem solved.

Community
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 20 '22 at 04:56
  • it's worked for me, thanks – Archi Patel Jul 06 '23 at 10:59