Which is better: require_once? or if (! defined ('FOOBAR')) is required? or something completely different?

Assuming the PHP version> = 5.2, which is the best management solution, includes:

require_once DEFPATH . 'config.inc.php';

or

if (!defined('FOOBAR')) require DEFPATH . 'config.inc.php';

or something completely different?

The site does not use a front-end controller or autoloader. A typical number of files to be included is 3 to 8.

I heard here and elsewhere that require_onceadds overhead and doesn't play well with caching. But I also heard that a small number of statements require_onceare normal in practice in later versions of PHP.

There should also be some overhead associated with the verification, if something is defined, but this may be less of a problem.

In general, what is best practice and why?

+3
3

, require_once() , . , , PHP -, , . , ! ( "FOOBAR" ) , .

PHP-, , . , , , , .

, , :

  • include() require()
  • .
  • ,

- - , - , .

: ! , 0 50 , .

+3

require_once . , , 8 . Require_once ""...

+2

, FOOBAR , . , .

, . PHP . , .

, , , , .

0

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


All Articles