Options versus OOP issue

I just started learning OOP, and I'm a little confused by the benefits of any functions or OOP. I understand that OOP is much more versatile in organizing your code, but, for example, I have 50 lines of code that appear on 7/10 pages of my site. Is it better to create a file and put the function in the file and then use include or do the same with the class? Also, are mass classes better in one file and include it? If anyone has some understanding that can help eliminate my confusion, I would really appreciate it.

+3
source share
3 answers

The relevant metric is utility.

, , .

- , , .

+3

50- , , .

, . .

+2

"" . ... , . . :

<?php 
class Group
{
  static public function func1() { }
  static public function func2() { }
}

Group::func1();
?>

PHP 5.3 :

<?php
namespace Group;

function func1() { }
function func2() { }
?>

<?php
// from a different file / global namespace:
Group\func1();
?>

Now about applying classes vs functions ... It's simple. If any group of functions "owns" the data or needs to remember some state, you almost definitely want to use the class.

+1
source

Source: https://habr.com/ru/post/1765905/


All Articles