简体   繁体   中英

php - Self function is called without defining it

I came across a function, which is being called without defining it anywhere. No error is shown from intelphense as well. function I am referring to in the below code is self::whereIdenityNumber($identityNumber)->exists();

public static function generateUniqueIdentityNumber()
{
    $identityNumber = strtoupper(Str::random(10));
    while (true) {
        $isExist = self::whereIdenityNumber($identityNumber)->exists();
        if ($isExist) {
            self::generateUniqueIdenityNumber();
        }
        break;
    }

    return $identityNumber;
}

There is no problem with the function, just wanted to know how it works.

note: there is a comment like below in docblock comments. Can this be treated as defining the function?

* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IdentityUser whereIdentityNumber($value)

That static method seems to be defined at \App\Models\IdentityUser

You must have something like:

Class IdentityUser extends Model{

  public static whereIdentityNumber($query){
   
   ...
  
  }


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM