Re: [PHP] Avoid object twice
- Date: Thu, 5 Jun 2008 02:28:24 +0900
- From: "Yui Hiroaki" <hiroakiyui@xxxxxxxxx>
- Subject: Re: [PHP] Avoid object twice
Thanks you for php developer.
If php can not share the parameter each different
file, it is not reality of my program.
If I use include or requre, php can share the paremeter each file.
But other files call or execute from original file.
setting.php and google_info.php and other.php almost reach
the my goal, I thought.
But google_info.php must execute mail() function.
Or setting.php must have $googlemapkey.
Thank you for a lot.
Regards,
Yui
2008/6/5 Boyd, Todd M. <tmboyd1@xxxxxxxx>:
>> -----Original Message-----
>> From: Yui Hiroaki [mailto:hiroakiyui@xxxxxxxxx]
>> Sent: Wednesday, June 04, 2008 10:03 AM
>> To: Thijs Lensselink
>> Cc: php-general@xxxxxxxxxxxxx
>> 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@xxxxxxxxxxx","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
>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php