PHP classes and including files

I need information on including files in PHP classes. EG.

include Foo2.php; //<--- Is this good?    
class Foo {
      function doFoo(){
         include("Foo2.php"); //<--- or is this better?
         //do something with vars from Foo2
      }
}

I was wondering what the differences were outside the scope, and whether there were other ways to include another php file in the class.

Thanks in advance for any answers.

+3
source share
2 answers

include in the global scope. It is very readable and serviceable.

+4
source

You can include PHP files only in functions of the class or outside the class, so you have both ways.

The difference is that inside the function will only be included if you call this function.

, , , , , , .

0

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


All Articles