2 Replies - 391 Views - Last Post: 23 April 2012 - 07:40 PM Rate Topic: -----

#1 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 817
  • Joined: 16-September 09

Calling function from different file

Posted 23 April 2012 - 07:04 PM

Hi guys!!

I'm getting fairly nifty at all this PHP stuff and I'm curious about expanding a bit...

This might sound dumb but I'm not sure how to attack it -- if at all.

If I had a function that pulled user data and put it in to variables and I wanted to write said function once and save it under "mysite.co/scripts_php/pull_user_data.php", could I call that function from any script? Would I have to use an include or a require prior to calling it or does the server automatically locate it and run it?

I might even be way off here but now I'm looking in to making my code a bit more efficient.

As always, thanks in advance!! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Calling function from different file

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2927
  • View blog
  • Posts: 10,114
  • Joined: 08-August 08

Re: Calling function from different file

Posted 23 April 2012 - 07:15 PM

You would need to include or require it.

Next you'll want to read up on classes.
Was This Post Helpful? 0
  • +
  • -

#3 floppyspace  Icon User is offline

  • D.I.C Regular

Reputation: 48
  • View blog
  • Posts: 254
  • Joined: 04-February 10

Re: Calling function from different file

Posted 23 April 2012 - 07:40 PM

As CTphpnwb says,
This link is a good example of the simplicity of calling a function to a page is, if from DB or just a .php. If you want more technical view have a look at WordPress (it is built with calls to various functions all happening at once)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1