错误:不应该静态调用,假设 $this 来自不兼容的上下文.只在我的机器上 [英] error :should not be called statically, assuming $this from incompatible context. only on my machine

查看:27
本文介绍了错误:不应该静态调用,假设 $this 来自不兼容的上下文.只在我的机器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队成员在控制器中静态编写了模型函数调用,例如:

My team members wrote the model function calls in the controller statically such as:

$data = ModelName::functionName($param);

虽然它应该被动态调用,例如:

while it should be called dynamically such as:

$model = new Model();
$data = $model->functionName($param);

大部分调用都是静态进行的.代码在服务器和他们的本地机器上运行,除了我的.如果不重写大量代码库,静态调用太多无法修复.

mostly all the calls are made statically. the code is working on the server and on their local machines except for mine. And the static calls are too many to fix without rewriting huge code base.

我总是通过作曲家更新我的项目.我的php版本是5.4.

I always update my project via composer. My php version is 5.4.

有人可能知道这是关于什么的吗?

anyone might know what this is about?

推荐答案

您可能在运行 PHP 时出现 E_STRICT 错误报告.尝试将其关闭,看看是否解决了问题 - 例如为 E_STRICT 错误报告错误.在 SO 上查看这篇文章:

You probably have PHP running with E_STRICT error reporting. Try turning it off and see if that fixed the problem - like turn of error reporting for E_STRICT errors. See this post on SO :

<?php
error_reporting(E_ALL ^ E_STRICT);

但我不得不说,混合使用对象样式和静态样式调用是个坏主意.函数调用应明确表明在静态或对象上下文中调用函数,并相应地采取行动.即使有点困难(对所有文件进行 grep 并更改错误调用有多难?),我建议您先修复您的代码.

But I have to say, it's a bad idea to mix object-style and static-style calls. Function calls should explicitly show that a function is called in a static or object context, and act accordingly. Even if it's a little hard (how hard is making a grep on all the files and change wrong calls?), i'd recommend fixing your code first.

而且我还建议您阅读面向对象中的 static 关键字编程 - 区分静态方法和对象方法调用是有原因的,不是让事情变得更容易"的原因,而是让事情变得更简单的原因事情更清楚了",我想说.

And also I recommend reading about static keyword in Object Oriented Programming - there's a reason to distinguish static and object method calls, and it's not a reason of "to make things easier", but more of a "to make things clearer", I'd say.

这篇关于错误:不应该静态调用,假设 $this 来自不兼容的上下文.只在我的机器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆