Re: Avoid object twice
| From: | Yui Hiroaki | Date: | Wed, 04 Jun 2008 13:42:12 +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-274997@lists.php.net to get a copy of this message | ||
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@ccis.edu>:
>> Thank you for your advice me!
>>
>> -------------My.php-------
>> <?php
>>
>> Class My{
>> private $word;
>> function __construct($getword){
>> $this->word=$getword;
>> }
>> public function buff(){
>> mail("aaa@example.com","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.
>
>
> Todd Boyd
> Web Programmer
>
>
>
>