Could someone please explain to me on when should one use the include and include_once and how should one be using it.
I am new to PHP and would like to understand this is laymans terms. Not too clear with whats mentioned on PHP documentation at php.net.
Let us say I have the following folder structure
–>Root–>API–>User.php
–>Root–>Users–>CreateUser.php
If I have to use the User.php in CreateUser.php how should I be doing it.
And if there is another file under
–>Root–>API–>Utility–>ImageProcessor.php
How should i being including ImageProcessor.php with CreateUser.php
If you always
include_onceeverything will be ok. It prevents including the same file twice.Let’s say you have these files:
c:include b; include a;b:include a;a:echo "hello";when you execute
c,awill be included twice (most probably an unwanted situation), therefore if you use all of them asinclude_onceit will be called only once.It comes with a little performance cost however if you are not Facebook or so, that is not a significant cost.