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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3f8e9-4485b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3f8e9-4485b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?