4

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.

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

anyone might know what this is about?

Dennis
  • 7,907
  • 11
  • 65
  • 115
tareq
  • 1,119
  • 6
  • 14
  • 28
  • 2
    Provide an example, please. Also, PHP 5.5 was released long ago, even 5.6 is out, so you should consider updating to a recent version eventually. – Ulrich Eckhardt Sep 15 '14 at 12:30
  • i updated my php version and that seems to solve the problem, thanks. @UlrichEckhardt – tareq Sep 15 '14 at 13:42

2 Answers2

8

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);

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.

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.

Community
  • 1
  • 1
Kleskowy
  • 2,648
  • 1
  • 16
  • 19
  • 1
    I agree, you are just hiding the problem this way. You should really change it to the proper way. – Mihai P. Sep 17 '14 at 00:42
  • 1
    There are performance implications in having these warnings, even if you turn off error reporting: See: http://stackoverflow.com/questions/1868874/does-php-run-faster-without-warnings – Adam Friedman Feb 09 '15 at 20:43
  • 1
    @AdamFriedman I think you mean: _there are performance implications in writing bad code_? ;) Thanks for the useful post, did not know that. – Kleskowy Feb 10 '15 at 00:26
  • Personally i like static function for their simple way of calling, without the need to initialization. And because some methods don't really require different "objects" instances they look good for API methods. So, I don't see anything wrong with them when they act as "universal/global/functional" functions. – Miguel Jan 05 '18 at 10:48
0

Sorry but I do not write English very well, but what I understand your question is that:

you need to put your static function:

static public function functionName () {

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

}

That happens through the different versions of PHP that the servers handle. I hope that I have understood your question and translate it well, because a similar error appeared to me and I solved it that way.

Vel
  • 9,027
  • 6
  • 34
  • 66