Re: Avoid object twice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Regards,
Yui

2008/6/4 Thijs Lensselink <dev@xxxxxxxx>:
> Quoting Yui Hiroaki <hiroakiyui@xxxxxxxxx>:
>
>> My problem is that I would like to share the parameter.
>> For instance, goolge map key.
>>
>> There are actually two files.
>>
>> example,
>>
>> main.php--------------------
>> <?php
>> $googlemapkey="g8ejeUFEUHEU";// example
>> mail("test@xxxxxxxxxxx","test"."test");
>> ?>
>>
>> Above is part of code;
>> I will excute main.php program.
>> then other.php run
>> But when other.php run, other.php requre $googlemapkey.
>> Of couse, I can get $googlemapkey if I use "include" or "require".
>> But if I use "include" or "require",
>> mail("test@xxxxxxxxxxx","test"."test") run again.
>>
>> So this program send twice email. It is NOT GOOD.
>> I juse send $googlemapkey from mail.php to other.php
>>
>>
>> Please advice if you have any solution.
>>
>>
>> Regards,
>> Yui
>>
>>
>> 2008/6/4 Boyd, Todd M. <tmboyd1@xxxxxxxx>:
>>>>
>>>> I knew it .
>>>>
>>>> But "Hello" and "Good" is different file.
>>>> I would like to get "Good" from b.php.
>>>>
>>>> Please tell me goo advice.
>>>> Yui
>>>>
>>>> 2008/6/4 Boyd, Todd M. <tmboyd1@xxxxxxxx>:
>>>> >> Thank you for your advice me!
>>>> >>
>>>> >> -------------My.php-------
>>>> >> <?php
>>>> >>
>>>> >> Class My{
>>>> >>        private $word;
>>>> >>        function __construct($getword){
>>>> >>             $this->word=$getword;
>>>> >>        }
>>>> >>        public function buff(){
>>>> >>             mail("aaa@xxxxxxxxxxx","test","test");
>>>> >>        }
>>>> >> }
>>>> >> ?>
>>>> >> ----------------------------------
>>>> >>
>>>> >> --------------b.php------------
>>>> >> <?php
>>>> >>   function __autoload($class_name) {
>>>> >>   include_once $class_name . '.php';
>>>> >>   }
>>>> >>
>>>> >>
>>>> >> $objref=new My("Good");
>>>> >> $objref->buff();
>>>> >> ?>
>>>> >> --------------------------------
>>>> >>
>>>> >> --------------c.php----------
>>>> >> <?php
>>>> >>   function __autoload($class_name) {
>>>> >>   include_once $class_name . '.php';
>>>> >>   }
>>>> >>
>>>> >> $obj=new My("Hello");
>>>> >> $obj->buff();
>>>> >> ------------------------------
>>>> >>
>>>> >> That is what I want to try.
>>>> >>
>>>> >> When c.php run, Mail() function run // < it is OK
>>>> >> When b.php run, it also run Mail() fuction. // it is NOT OK
>>>> >>
>>>> >> I would like to run Mail() function one time only from c.php.
>>>> >> However I also get prameter which declare "Good" in b.php
>>>> >>
>>>> >> Now when c.php and b.php run, the program send twice email. That is
>>>> > not
>>>> >> good!!
>>>> >> I would like to run c.php and b.php, then the program, which is
>>>> Mail()
>>>> >> function, get one email and get  "Good"  from b.php
>>>> >
>>>> > You are not making any sense... if you only want the Mail() function
>>>> to
>>>> > run once, then ONLY CALL ->BUFF() ONE TIME. It's that simple. You
>>>
>>> are
>>>>
>>>> > mailing twice because you call buff() in two separate places--and
>>>> buff()
>>>> > in turn calls Mail(). I don't understand your problem.
>>>> >
>>>> > $objref = new My("Good");
>>>> > $obj = new My("Hello");
>>>> > $obj->buff();
>>>> >
>>>> > Bam. You get Hello, Good, and it sends one e-mail. Since you are
>>>> > completely abstracting your code from its real-world application,
>>>> that's
>>>> > the best I can do.
>>>
>>> I still don't get it. Please explain to me WHY this is not a solution to
>>> your problem?
>>>
>>> ===
>>> My.php
>>> ===
>>> <?php
>>> Class My{
>>>      private $word;
>>>      function __construct($getword){
>>>           $this->word=$getword;
>>>      }
>>>      public function buff(){
>>>           mail("aaa@xxxxxxxxxxx","test","test");
>>>      }
>>> }
>>> ?>
>>>
>>> ===
>>> b.php
>>> ===
>>> <?php
>>>       function __autoload($class_name) {
>>>               include_once $class_name . '.php';
>>>       }
>>>
>>>       $objref=new My("Good");
>>>       // $objref->buff(); NOTICE HOW THIS IS COMMENTED OUT!!!
>>> ?>
>>>
>>> ===
>>> c.php
>>> ===
>>> <?php
>>>       function __autoload($class_name) {
>>>               include_once $class_name . '.php';
>>>       }
>>>
>>>       $obj=new My("Hello");
>>>       $obj->buff();   // MAIL() IS EXECUTED HERE
>>> ?>
>>>
>>> If that doesn't work, then here are my questions:
>>>
>>> 1.) What on earth are you ACTUALLY trying to do?
>>> 2.) Does ->buff() NEED to be called for each instance of My()?
>>> 3.) Are you wanting multiple instances of this class to share data?
>>> 4.) If (3), then are you familiar with the STATIC property?
>>>
>>>
>>> Todd Boyd
>>> Web Programmer
>>>
>>
>
> 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.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux