Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static or not static?

Tags:

oop

php

What is better to use in this context, static methods, or simple public method and call them always like this: $request = new Request(); if($request->isPostRequest()){ do smth } ofcourse its easier to use static, but what is more properly to use?

Class Request {
 public static function isSecureConnection() {}
 public static function isPostRequest() {}
 public static function isAjaxRequest() {}
 ...etc

}
like image 527
Vlad Avatar asked Aug 08 '10 06:08

Vlad


1 Answers

If each Request is a genuine entity, then it would be better to use non-static members. But if it's not and methods are used in general, like Sinus function in math, then they'd be better to be static.

Overall it'd be better to declare static functions in a class that is just consisted of functions and no data members.

like image 91
Hamid Nazari Avatar answered Sep 28 '22 13:09

Hamid Nazari