Re: Avoid object twice

From: Date: Wed, 04 Jun 2008 16:21:47 +0000
Subject: Re: Avoid object twice
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.general 
Request: Send a blank email to php-general+get-275018@lists.php.net to get a copy of this message
Thank you for all! I try to use script. But it does not run correctly. It means that setting.php never call sendMail() from google_info.php. Are you sure that it is possible to call function from other file? Best Regards, Yui 2008/6/5 Boyd, Todd M. <tmboyd1@ccis.edu>: >> -----Original Message----- >> From: Yui Hiroaki [mailto:hiroakiyui@gmail.com] >> Sent: Wednesday, June 04, 2008 10:03 AM >> To: Thijs Lensselink >> Cc: php-general@lists.php.net >> Subject: Re: [PHP] Avoid object twice >> >> NO! >> That is what I do not want! >> setting.php need to run mail() function. >> also setting.php need $googlemapkey. >> >> other.php just need $googlemapkey. >> other .php do not need run mail() function. >> >> If I use "include", I will get twice email. >> >> Please do advice how to share the $googlemapkey. >> >> > I think you are making it way to complicated for yourself. >> > >> > So you really just need to share settings between files. >> > That's exactly what include / require are for. >> > >> > settings.php >> > <?php >> > $googlemapkey = "g8ejeUFEUHEU";// example >> > >> > function sendMail() { >> > mail("test@example.com","test"."test"); >> > } >> > ?> >> > >> > >> > Here you include settings.php and are able to use the mapkey >> variable. >> > If you want to send an email just call sendMail(); >> > >> > other.php >> > <?php >> > include "settings.php"; >> > >> > // use your google API key any way you want >> > >> > sendMail(); // sends mail >> > ?> >> > >> > If you don't need the sendMail(); function. then don't call it. >> > other2.php >> > <?php >> > include "settings.php"; >> > >> > // use your google API key any way you want >> > ?> >> > >> > >> > I think that's about as clear as i can make it. > > For the love of everything good in this world, please take the time to > READ his reply. Most notably, you should pay attention to how he > DECLARES a function in "settings.php", rather than EXECUTING a function. > Since it is just a DECLARATION, you can include that file and the > function will not be EXECUTED. You can then EXECUTE the function at a > time of your choosing. > > Not everything should run when it is loaded--you built a class ("My")... > this is the same idea. Rather than a class, this is a function. Think > about it--member functions of classes don't execute by themselves (save > for the constructor/destructor, etc.)... you have to invoke them. Same > with (most) functions. You build it, and then it just sits there until > you actually tell it to do something. If you don't want your script to > send mail yet, then don't tell it to use the sendMail() function. > > Hope this is resolved, > > > Todd Boyd > Web Programmer > > >

« previous php.general (#275018) next »