Re: SV: SV: [PHP] Including files without loosing my string

2001-09-25 Thread David Robley

On Tue, 25 Sep 2001 17:46, Bård Tommy Nilsen wrote:
> Can you write me an short example ??
>
>
> Bård Tommy Nilsen

[About passing arguments to functions and global scoping]

Declaring $id global:

function doit() {
 global $id;
 echo $id;
}

$id = 1;
doit();
output is 1

Passing $id as parameter:

function doit($input) {
 echo $input;
}

$id = 1;
doit($id);
output is 1

See the sections of the manual on Functions and variable scope for more 
information.
 
-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   printf("to C or not to C...that is the question/n");

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




SV: SV: [PHP] Including files without loosing my string

2001-09-25 Thread Bård Tommy Nilsen



Can you write me an short example ??


Bård Tommy Nilsen



-Opprinnelig melding-
Fra: David Robley [mailto:[EMAIL PROTECTED]]
Sendt: 25. september 2001 10:11
Til: Bård Tommy Nilsen; [EMAIL PROTECTED]
Emne: Re: SV: [PHP] Including files without loosing my string


On Tue, 25 Sep 2001 17:32, Bård Tommy Nilsen wrote:
> Thats only if i call the index.php file first.
> For that i have another solution
> if (function_exists('func')) {
> call_user_func ('func');
> } else {
> include 'main.php';
>
> But thats not the problem.
>
> I am using id in an sql query, but not shown in my example (sorry :) )
> But i wanted to show what i am after, and that is that the
> id string cant be called after including index.php ...
>
>
> Bård Tommy Nilsen

If you want to access id, you know that it is available as $id; but if
you want it accessible within the function, you either have to pass it to
the function as a parameter or delcare it as global within the function.

>
>
> -Opprinnelig melding-
> Fra: David Robley [mailto:[EMAIL PROTECTED]]
> Sendt: 25. september 2001 09:56
> Til: Bård Tommy Nilsen; [EMAIL PROTECTED]
> Emne: Re: [PHP] Including files without loosing my string
>
> On Tue, 25 Sep 2001 17:01, Bård Tommy Nilsen wrote:
> > Hello !
> >
> > I am trying to keep my string after including av file.
> >
> > file1.php:
> > (accessed with file1.php?id=1)
> >
> >  > include 'index.php';
> >
> > function func() {
> > echo "buddy";
> > }
> > ?>
> >
> > index.php:
> >  > echo "Hello";
> > if (function_exists('func')) {
> > call_user_func ('func');
> > }
> >
> > The output should then be "Hello buddy";
> >
> > Can anyone help me with this one ??
> >
> > Regards
> > Bård Tommy Nilsen
>
> In most languages, you must declare a function _before_ calling it. In
> your case, your program looks like this after the include:
>
>  // include 'index.php';
> echo "Hello";
>  if (function_exists('func')) {
>  call_user_func ('func');
> }
>  function func() {
>  echo "buddy";
>  }
>
> So you have no function at the time you test for it :-)
>
> --
> David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
> CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA
>
>Useless Invention: Rollerblade skates for peglegs.

--
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA

   "Unto thee," Jesus said verily.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: SV: [PHP] Including files without loosing my string

2001-09-25 Thread David Robley

On Tue, 25 Sep 2001 17:32, Bård Tommy Nilsen wrote:
> Thats only if i call the index.php file first.
> For that i have another solution
> if (function_exists('func')) {
> call_user_func ('func');
> } else {
> include 'main.php';
>
> But thats not the problem.
>
> I am using id in an sql query, but not shown in my example (sorry :) )
> But i wanted to show what i am after, and that is that the
> id string cant be called after including index.php ...
>
>
> Bård Tommy Nilsen

If you want to access id, you know that it is available as $id; but if 
you want it accessible within the function, you either have to pass it to 
the function as a parameter or delcare it as global within the function.

>
>
> -Opprinnelig melding-
> Fra: David Robley [mailto:[EMAIL PROTECTED]]
> Sendt: 25. september 2001 09:56
> Til: Bård Tommy Nilsen; [EMAIL PROTECTED]
> Emne: Re: [PHP] Including files without loosing my string
>
> On Tue, 25 Sep 2001 17:01, Bård Tommy Nilsen wrote:
> > Hello !
> >
> > I am trying to keep my string after including av file.
> >
> > file1.php:
> > (accessed with file1.php?id=1)
> >
> >  > include 'index.php';
> >
> > function func() {
> > echo "buddy";
> > }
> > ?>
> >
> > index.php:
> >  > echo "Hello";
> > if (function_exists('func')) {
> > call_user_func ('func');
> > }
> >
> > The output should then be "Hello buddy";
> >
> > Can anyone help me with this one ??
> >
> > Regards
> > Bård Tommy Nilsen
>
> In most languages, you must declare a function _before_ calling it. In
> your case, your program looks like this after the include:
>
>  // include 'index.php';
> echo "Hello";
>  if (function_exists('func')) {
>  call_user_func ('func');
> }
>  function func() {
>  echo "buddy";
>  }
>
> So you have no function at the time you test for it :-)
>
> --
> David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
> CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA
>
>Useless Invention: Rollerblade skates for peglegs.

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   "Unto thee," Jesus said verily.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




SV: [PHP] Including files without loosing my string

2001-09-25 Thread Bård Tommy Nilsen


Thats only if i call the index.php file first.
For that i have another solution
if (function_exists('func')) {
call_user_func ('func');
} else {
include 'main.php';

But thats not the problem.

I am using id in an sql query, but not shown in my example (sorry :) )
But i wanted to show what i am after, and that is that the
id string cant be called after including index.php ...


Bård Tommy Nilsen


-Opprinnelig melding-
Fra: David Robley [mailto:[EMAIL PROTECTED]]
Sendt: 25. september 2001 09:56
Til: Bård Tommy Nilsen; [EMAIL PROTECTED]
Emne: Re: [PHP] Including files without loosing my string


On Tue, 25 Sep 2001 17:01, Bård Tommy Nilsen wrote:
> Hello !
>
> I am trying to keep my string after including av file.
>
> file1.php:
> (accessed with file1.php?id=1)
>
>  include 'index.php';
>
> function func() {
> echo "buddy";
> }
> ?>
>
> index.php:
>  echo "Hello";
> if (function_exists('func')) {
> call_user_func ('func');
> }
>
> The output should then be "Hello buddy";
>
> Can anyone help me with this one ??
>
> Regards
> Bård Tommy Nilsen

In most languages, you must declare a function _before_ calling it. In
your case, your program looks like this after the include:

http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]