Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Classes and including files

Tags:

include

php

class

I am needing some information on including files in PHP classes. E.G.

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 beside scope and if there were any other ways to include another php file in a class.

Thanks in advance for any responses.

like image 968
Mozez Avatar asked Apr 27 '26 05:04

Mozez


1 Answers

include at the global scope. It's much readable and maintainable.

like image 140
erenon Avatar answered Apr 29 '26 20:04

erenon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!