解决TP5.1 报错:Non-static method think\Cookie::get() should not be called statically...

本文解决了在ThinkPHP框架中,Controller类内使用非静态方法thinkCookie::get()时出现的错误:不应静态调用非静态方法。通过将静态方法调用改为助手函数调用的方式,成功避免了这一问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在Controller类中获取Cookie时完整的报错:

Non-static method think\Cookie::get() should not be called statically, assuming $this from incompatible context

 百度翻译过来的意思:假设$this来自不兼容的上下文,则不应静态调用非静态方法think\cookie::get()。

 

原本的在Controller类中,获取Cookie时是用静态方法获取的:

Cookie::get('name');

改成用助手函数获取就好了:

cookie('name');

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值