Use include or constants to pick up codes?

Asked

Viewed 47 times

3

I have created a file containing patterns that are used in my system. I would like to know what is the difference in performance between calling the code by a include or by a constante thus:

//código do incluir.php: <a href=""></a>

include "incluir.php";
define('_CONSTANT','<a href=""></a>');

Has some advantage in using one and the other?

I ask this because I am in doubt if using one or the other can affect the performance of my system, since I use it enough to pick up standard codes

1 answer

4


The question is very objective about which of the two is more performatic. Therefore, I will not comment on concepts or data structure (mvc, Oop, etc) and not even good programming practices.

Answering objectively, within its context, is faster by defining constants. Simple like this.

The reason is obvious. The process of including a file consumes memory and runtime to load the same value that would be in a constant. So if you can use constants, use them.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.