There is a construction of the form:

class EmailSendPassword extends Mailable { use Queueable, SerializesModels; public $user; public $password; public function __construct($user, $password) { $this->user = $user; $this->password = $password; } public function build() { return $this ->subject('Ваш пароль на сайте ' . env('APP_NAME')) ->markdown('emails.sendpass', compact('user', 'password')); } } 

So, the compact function starting with php 7.3 starts to generate an error related to the fact that the user variable is not defined. In the documentation regarding changes in php 7.3 related to the compact function, only this remark:

compact () now it makes it possible to make a list of variables. Formerly, such strings have been silently skipped.

Tell me, what is the error? Of course, if you set $user = $this->user in the build() method, the problem is solved, but how can you do without these crutches?

  • one
    I wonder how you adequate code called a crutch. I would on the contrary use compact called a crutch. Oddly enough, writing a variable name in the form of a string literal will eventually lead to a typo and jambs in the code. It makes sense sometimes, but do not abuse it and shove it anywhere. Especially since it takes variables from the dblbvjcnb domain, it will not return class members to you. - teran
  • As far as I remember, compact did not see any public properties in one version -
  • @ Dmitri, you're wrong. Find off. the source is that compact can push public properties of a class into an associative array. Maybe some "teacher" prompted you? Look at the screen from @u_mulder in the comments under my answer - Maxim K

1 answer 1

That's right, nothing was output to php7.3 if the variable is not defined, so it was fixed. Those. in fact, without the variables defined by this obscure, by calling compact('definedVar','undefinedVar1','undefinedVar2') we received an associative array of only those variables that are available in the current scope

And my subjective opinion is that this is not entirely correct.

Correspondingly, when calling compact your code did not pass variables to the view. What, in principle (I think) is not exactly what is expected.

Therefore, in each case, the pursuit of the beauty of the code should not be forgotten about its performance. This is how it will work:

 public function build() { return $this ->subject('Ваш пароль на сайте ' . env('APP_NAME')) ->markdown('emails.sendpass', [ 'user' => $this->user, 'password' => $this->password ]); } 

And this is certainly not a crutch.

  • So the problem is not that it returns null, but that the compact function, prior to the php 7.3 version, saw the public property of the class, and now it does not. - Denis
  • 3
    3v4l.org/cPkVK - u_mulder is not visible in any of the versions of the public variable
  • @u_mulder is interesting, and the truth is not visible, moreover, I had distorted ideas about the use of public properties of the class. Mysticism is that it worked in my project before updating the version of php, now I find out how :) - Denis
  • @ Denis yes admit that you transferred the code to another method, and there used to be some function input parameters. - teran
  • @teran mm, no. - Denis