 |
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6  | This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 9th, 2004, 08:02 AM
|
|
Authorized User
|
|
Join Date: May 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Functions - Now Answered Thank you
Call someone please tell me what the data in side the brackets after a function name is for.
ie :
function get_director()
....
....
get_director($movie_name)
What does the ($movie_name) bit do?
Thanks guys
|
|

June 9th, 2004, 08:28 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
|
|
It is a variable which is passed into the function.
Inside the function that variable can be used.
Om Prakash
|
|

June 9th, 2004, 09:12 AM
|
|
Authorized User
|
|
Join Date: May 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So, if they brackets were empty, then that variable couldn't be used inside the function then?
If that is the case, why do you need:
global $movie_name;
I thought using the above global line allowed the function to use external variables, and allow variables created inside the function to be used outside the function!
Now I'm really confused.
Could you clear this one up for me.
Thanks a bunch !
|
|

June 9th, 2004, 09:55 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2004
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
A function has what is called arguments: Functioname(argument1, argument2, argument3). When you call the function those arguments(values) get store in variables which are the variables you see when the function is defined:
Function Functioname($argument1, $argument2, $argument3)
{
}
If you have no arguments there is no way you can pass values to a function except by using globals which from my experience in java(the don't have globals per se) should be used sparely.
Hope this helps.
CHristian
|
|

June 9th, 2004, 11:13 AM
|
|
Authorized User
|
|
Join Date: May 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, things are a little clearer now.
So:
On page 118 of the book there is a file called table 2. This file has a function that are written as follows:
function get_director()
{
global $movie_director;
.......
}
This function is called later on in the script by the following:
//get director's name from the people table
get_director($movie_director)
Could someone please confirm that the following that I think happens is true:
The variable $movie_director is passed to the function when it is called. Therefore the function can now use this variable. If the $movie_director wasn't included within the brackets when the function was called, then the function could not use it, even though the function has the line "global $movie_director".
If this is the case, why do you need the "global $movie_director".
As well as the above question, am I right in saying that if the function read:
function get_director($anyname)
{
global $movie_director;
.......
}
then the $movie_director variable passed when the function was called, would now become known as $anyname ?
Sorry if this sounds a bit basic, but I'm a newbie who really wants to understand this bit before I move onto the next page.
Thanks guys
|
|

June 9th, 2004, 12:02 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You are correct in how arguments work...
example:
function foo($b)
{
// Some logic
}
// Call the function
$a = "bar";
foo($a);
... When using a variable as an argument, it's value becomes available inside the function as the name of the argument (value of $a is available inside the function as $b).
However, in the code example you are referencing, it looks just like a versioning/typo/error problem the code. You should be able to call the function without arguments: get_director();
Let me know if you've any more questions.
|
|

June 9th, 2004, 12:11 PM
|
|
Authorized User
|
|
Join Date: May 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by jason.gerner
...in the code example you are referencing, it looks just like a versioning/typo/error problem the code. You should be able to call the function without arguments: get_director();
|
Yeah... I'm surprised the tech editor didn't catch that one, aren't you?
BuzzLY
aka Michael K. Glass
Author, Beginning PHP, Apache, MySQL Web Development
|
|

June 9th, 2004, 12:13 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yeah, we'll have to find that guy and go over to my, errr his house and beat him. :)
|
|

June 9th, 2004, 12:14 PM
|
|
Authorized User
|
|
Join Date: May 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
LOL
BuzzLY
aka Michael K. Glass
Author, Beginning PHP, Apache, MySQL Web Development
|
|

June 9th, 2004, 12:49 PM
|
|
Authorized User
|
|
Join Date: May 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Right, so you can call this particular function as:
get_director()
instead of
get_director($movie_name)
By doing this though, can the function still use the $movie_name variable?
Or is it because the function has "global $movie_name" that it can use it?
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Functions |
LTello |
BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 |
3 |
September 15th, 2006 11:15 AM |
| Functions |
czambran |
BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 |
13 |
July 11th, 2006 06:33 PM |
| answered information bar |
Seeker55 |
Javascript |
1 |
March 28th, 2006 01:42 AM |
| extract function - Now answered Thank You |
thegooner |
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 |
3 |
June 11th, 2004 06:44 AM |
|
 |