8 Replies - 2079 Views - Last Post: 18 February 2005 - 04:38 PM Rate Topic: -----

#1 SpaceMan   User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

To Function Or Not To Function

Posted 17 February 2005 - 02:53 PM

Howdy,

what the difference between
require "global.php";
require ("global.php");

or,

echo, print, etc.......


Is This A Good Question/Topic? 0
  • +

Replies To: To Function Or Not To Function

#2 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: To Function Or Not To Function

Posted 17 February 2005 - 03:12 PM

Good question. The require() call does not seem to distinguish...coding standards maybe?
Was This Post Helpful? 0
  • +
  • -

#3 SpaceMan   User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: To Function Or Not To Function

Posted 17 February 2005 - 03:52 PM

Amadeus, on Feb 17 2005, 03:12 PM, said:

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

so it does not mater eather way?

same thing?
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: To Function Or Not To Function

Posted 17 February 2005 - 05:46 PM

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?
Was This Post Helpful? 0
  • +
  • -

#5 mstyle   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 16
  • Joined: 25-October 04

Re: To Function Or Not To Function

Posted 18 February 2005 - 02:24 PM

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.
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: To Function Or Not To Function

Posted 18 February 2005 - 02:54 PM

I belive he was asking the difference between calling require() with the brackets, or using the quotes...I could be very wrong about that.
Was This Post Helpful? 0
  • +
  • -

#7 supersloth   User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4694
  • View blog
  • Posts: 28,512
  • Joined: 21-March 01

Re: To Function Or Not To Function

Posted 18 February 2005 - 03:00 PM

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.
Was This Post Helpful? 0
  • +
  • -

#8 cyberscribe   User is offline

  • humble.genius
  • member icon

Reputation: 10
  • View blog
  • Posts: 1,062
  • Joined: 05-May 02

Re: To Function Or Not To Function

Posted 18 February 2005 - 03:54 PM

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

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.robertpea...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.
Was This Post Helpful? 0
  • +
  • -

#9 supersloth   User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4694
  • View blog
  • Posts: 28,512
  • Joined: 21-March 01

Re: To Function Or Not To Function

Posted 18 February 2005 - 04:38 PM

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1