Just a point to make, the include, incude_once and require equivalents are not functions and therefore do not need the parenthesis around the pathname.
I am unsure of the origin of this bad habit.
I was just wondering about this, as I have always seen it with parenthesis but today I saw a code snippet somewhere that didn’t have them so I am glad I have this clear now.
well David, it’s obviously an alternative to use parenthesis and completely optional, it doesn’t make it any more correct or incorrect. Someone might have the same argument about spaces before and after brackets and colons in CSS.
I know it is optional but I bet that newcomers believe that require and include are functions because of the parenthesis. It does add confusion in my opinion.
If you have a look at the official documentation you can see the official examples do not use parenthesis and it also cautions you on the use of parenthesis in certain situations. http://us.php.net/manual/en/function.include.php
Although it does not create any difference whether using parenthesis or not. But really it can make difference in some situation. Visit David provided link again and give attention to example #5:
I can’t seem to get this snippet to work in my WAMP install. Would like to get this to work so that I can call my includes from other directories.
Warning: include_once(C:/wamp/www//common/header.php) [function.include-once]: failed to open stream: No such file or directory in C:\wamp\www\yourhearing\index.php on line 4
If I remove the line include_once($path);, it works for the main index.php, but this will not work in any other directory.
I am still having an issue with pulling in my css and js for my other pages. I want to type mydomain.com/otherpage/ and pull in my css and js by include with head.php but when it includes the head it only displays the content and not the styling or js. Any ideas?
Just a point to make, the include, incude_once and require equivalents are not functions and therefore do not need the parenthesis around the pathname.
I am unsure of the origin of this bad habit.
I was just wondering about this, as I have always seen it with parenthesis but today I saw a code snippet somewhere that didn’t have them so I am glad I have this clear now.
Thanks!
well David, it’s obviously an alternative to use parenthesis and completely optional, it doesn’t make it any more correct or incorrect. Someone might have the same argument about spaces before and after brackets and colons in CSS.
I know it is optional but I bet that newcomers believe that require and include are functions because of the parenthesis. It does add confusion in my opinion.
If you have a look at the official documentation you can see the official examples do not use parenthesis and it also cautions you on the use of parenthesis in certain situations.
http://us.php.net/manual/en/function.include.php
Although it does not create any difference whether using parenthesis or not. But really it can make difference in some situation. Visit David provided link again and give attention to example #5:
http://php.net/manual/en/function.include.php
I also have written an article, describing the difference between include and include_once, require etc.
http://www.techmug.com/php-basics-for-beginners/
I can’t seem to get this snippet to work in my WAMP install. Would like to get this to work so that I can call my includes from other directories.
Warning: include_once(C:/wamp/www//common/header.php) [function.include-once]: failed to open stream: No such file or directory in C:\wamp\www\yourhearing\index.php on line 4
If I remove the line
include_once($path);
, it works for the main index.php, but this will not work in any other directory.Any help is appreciated, THANKS.
DIRECTORY STRUCTURE:
/inc
/js
/css
/img
index.php
Never mind, I had a typo.
I am still having an issue with pulling in my css and js for my other pages. I want to type mydomain.com/otherpage/ and pull in my css and js by include with head.php but when it includes the head it only displays the content and not the styling or js. Any ideas?
I’m having the same issue as Digitalvaldosta. Content shows up, but not JS or CSS.
hey i love your theme man
Using include without using parenthesis, my css wasn’t showing up, when I added parenthesis everything worked perfectly!
Very interesting and refreshing article.
I have used incude in the past, but now I want to use it in a responsive designand it doesn’t work at all.
My include line is:
http://codepen.io/anon/pen/YXXZMw.html
My footer.php is located in the same folder:
…
http://codepen.io/anon/pen/waaJOe.html
…
The page shows no footer a all.
:(
This is going to sound REALLY dumb, but is dynamic includes still a thing?