Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,463 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,387 people online right now. Registration is fast and FREE... Join Now!




To Function Or Not To Function

 
Reply to this topicStart new topic

To Function Or Not To Function, that is the question.

SpaceMan
post 17 Feb, 2005 - 01:53 PM
Post #1


D.I.C Regular

Group Icon
Joined: 20 Feb, 2003
Posts: 270

Howdy,

what the difference between
CODE

require "global.php";
require ("global.php");

or,

echo, print, etc.......
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 17 Feb, 2005 - 02:12 PM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,173



Thanked 33 times

Dream Kudos: 25
My Contributions


Good question. The require() call does not seem to distinguish...coding standards maybe?
User is offlineProfile CardPM

Go to the top of the page

SpaceMan
post 17 Feb, 2005 - 02:52 PM
Post #3


D.I.C Regular

Group Icon
Joined: 20 Feb, 2003
Posts: 270

QUOTE(Amadeus @ Feb 17 2005, 03:12 PM)
Good question. The require() call does not seem to distinguish...coding standards maybe?

so it does not mater eather way?

same thing?
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 17 Feb, 2005 - 04:46 PM
Post #4


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,173



Thanked 33 times

Dream Kudos: 25
My Contributions


It looks as if they're the same, but I could be wrong. It may accept all formats for backwards compatability, or maybe that type of statement was never strongly defined...maybe skyhawk, sloth or cyberscribe know?
User is offlineProfile CardPM

Go to the top of the page

mstyle
post 18 Feb, 2005 - 01:24 PM
Post #5


New D.I.C Head

*
Joined: 25 Oct, 2004
Posts: 16

The advantage of require to echo etc. is that you can use vars (like configs, templates) more often without needing it to program into every page you need it.
Also once you do it this way you will only have to change 1 file and have the changes be taken throughout all pages where that file is being required.
So there can be an advantage if there's a purpose for it. It won't make much of a difference on one page if only for making the code more accessible.
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 18 Feb, 2005 - 01:54 PM
Post #6


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,173



Thanked 33 times

Dream Kudos: 25
My Contributions


I belive he was asking the difference between calling require() with the brackets, or using the quotes...I could be very wrong about that.
User is offlineProfile CardPM

Go to the top of the page

supersloth
post 18 Feb, 2005 - 02:00 PM
Post #7


serial frotteur

Group Icon
Joined: 21 Mar, 2001
Posts: 19,514



Thanked 11 times

Dream Kudos: 2147483647

Expert In: being gentlemanly

My Contributions


I took it the way amadeus did.

I never really noticed, but I always the the ()'s out of habit. That was one of the weird things about moving to coldfusion because it almost exsclusively uses the ""s.
User is online!Profile CardPM

Go to the top of the page

cyberscribe
post 18 Feb, 2005 - 02:54 PM
Post #8


humble.genius

Group Icon
Joined: 5 May, 2002
Posts: 1,062



Thanked 2 times

Dream Kudos: 154
My Contributions


According to the Pear coding standards, the correct form is actually:

CODE

require 'global.php';


Because:
  • Require is not a function but more of a built-in directive
  • Single quotes are preferred for strings with no special characters or variables to evaluate
I'm currently writing a 3-part entry on practical coding standards:

http://www.robertpeake.com/archives/39-Pra...s-Part-1-3.html

Because some standards are really useful and some are just a matter of style. I'm trying to distill it out.
User is offlineProfile CardPM

Go to the top of the page

supersloth
post 18 Feb, 2005 - 03:38 PM
Post #9


serial frotteur

Group Icon
Joined: 21 Mar, 2001
Posts: 19,514



Thanked 11 times

Dream Kudos: 2147483647

Expert In: being gentlemanly

My Contributions


I think my habit too is coming from a c++ background, especially since i tended to lean towards system commands in a lot of my work.
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 01:23PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month