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

From: Date: Tue, 25 Sep 2001 08:11:24 +0000
Subject: Re: SV: [PHP] Including files without loosing my string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-68661@lists.php.net to get a copy of this message
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:huntsman@www.nisu.flinders.edu.au] > Sendt: 25. september 2001 09:56 > Til: Bård Tommy Nilsen; php-general@lists.php.net > 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) > > > > <?php > > include 'index.php'; > > > > function func() { > > echo "buddy"; > > } > > ?> > > > > index.php: > > <?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: > > <?php > // 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.

« previous php.general (#68661) next »