Re: Avoid object twice
| From: | Jim Lucas | Date: | Mon, 02 Jun 2008 16:00:08 +0000 |
| Subject: | Re: Avoid object twice | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274926@lists.php.net to get a copy of this message | ||
Yui Hiroaki wrote:
Please take a look at code. --------a.php-------- $obj=new my("Hello"); $obj->buff(); Class my{ private $word; function __construct($getword){Just to make sure, you are calling your a.php script my.php in real life right? If not, this might be part of your problem. When I run the above script, and change the a.php to my.php, it loads just fine and it only displays one instance of hello. I am thinking that you calling the class more then once and you don't realize it. -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare$this->word=$getword;} public function buff(){echo $this->word."<br />";} -------------------------------------- -----b.php----------------------- function __autoload($class_name) {include_once $class_name . '.php';} $objref=new my("Good"); $objref->buff(); -------------------------------------------- I get an Echo; Good Hello Hello I do not need to get Hello twice. When I b.php , $obj=new my("Hello") is loaded. Do you have any adia to avoid load $obj in a.php twice? Regards, Yui