Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in PHP. How to convert array to string in PHP? Blackbam An answer after 7 years for This question was asked seven years ago, and none of answers provide practical help for the question. Felix Kling Felix Kling k gold badges silver badges bronze badges. Brian Brian 91 1 1 bronze badge. When should one use require or include?
Akshay Khale Akshay Khale 7, 7 7 gold badges 45 45 silver badges 56 56 bronze badges. Require critical parts, like authorization and include all others. Your Common Sense Your Common Sense k 35 35 gold badges silver badges bronze badges. Marcx Marcx 6, 4 4 gold badges 43 43 silver badges 69 69 bronze badges.
I have to call this doSomething function from another PHP script file. Prashant Prashant 4, 4 4 gold badges 31 31 silver badges 70 70 bronze badges. Ferdinand Beyer Ferdinand Beyer Rukmi Patel Rukmi Patel 2, 8 8 gold badges 27 27 silver badges 41 41 bronze badges.
Pang 8, gold badges 82 82 silver badges bronze badges. Use require function when you need to load any class, function, or dependency. James Wong James Wong 21 2 2 bronze badges. Rotimi Rotimi 4, 4 4 gold badges 17 17 silver badges 27 27 bronze badges. They are all ways of including files. Here's concrete example; elaborating on what pcj said. Say you have a configuration file storing your database username and password conf. Adam Winter Adam Winter 1, 1 1 gold badge 8 8 silver badges 21 21 bronze badges.
Bink Bink 4 4 bronze badges. I know it's a late comment, but this is actually not true. Just use require and include. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Create account Log in. Twitter Facebook Github Instagram Twitch. Upload image. Submit Preview Dismiss. A curious and hardworking student developer with a passion for FOSS, side projects, designing and building applications, and sharing experiences.
Including a file produces the same result as copying the script from the file specified and pasted into the location where it is called. You can save a lot of time and work through including files — Just store a block of code in a separate file and include it wherever you want using the include and require statements instead of typing the entire block of code multiple times.
A typical example is including the header, footer and menu file within all the pages of a website. The basic syntax of the include and require statement can be given with:. Tip: Like the print and echo statements, you can omit the parentheses while using the include and require statements as demonstrated above.
0コメント