TP5 verifies how to use cookie? in a class

add public $uid=Cookie::get ("uid") to the validation class and you will get an error. Why? Can"t cookie be used this way?

<?php
namespace app\index\validate;

use think\Validate;
use think\facade\Cookie;

class User extends Validate
{
    public $uid=Cookie::get("uid");
    protected $rule =   [
        "uid"   => "number|between:1,120",
    ];
}
    

Mar.19,2021

should be
use think\ Cookie
bar


look here
definition of variables within the class


Brother, this is not a simple mistake, the pop-up system has an error, indicating that your use is not standard.
I don't usually assign values like you do. I always assign values through constructors and then this- > uid = Cookie::get ('uid').
I don't know if I can assign values like you do. But what you're doing is unscientific.

Menu