I have a Laravel 4.2 application which works with PHP5 without any problems. Since I installed a new vagrant box running PHP7 an error appears as soon as I run a model where the name of a function is the same as the class name (relationship-function) like this:
<?php
use IlluminateDatabaseEloquentSoftDeletingTrait;
class Participant extends Eloquent
{
use SoftDeletingTrait;
[...]
public function participant()
{
return $this->morphTo();
}
[...]
}
I get the following error message:
Methods with the same name as their class will not be constructors in a future version of PHP; Participant has a deprecated constructor (View: ...)
So what I didn't know until today is, that in PHP4 methods with the same name were the contructor of a class. Hmm. I am really a bad programmer... But in this case, from my understanding of what is happening in PHP7, they correct a failure of mine as I never wanted to use this function as a constructor, since it defines only an Eloquent relationship.
But how can I get rid of this message? As I understand this, in PHP4 my code was buggy, but not in PHP7, right? If not necessary I do not want to refactor this function, as it is used in several places.
Can anybody explain what I am doing wrong and why it worked with older PHP versions?
Thanks!
See Question&Answers more detail:os