Re: Avoid object twice

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

 



On 3 Jun 2008, at 17:12, Yui Hiroaki wrote:
The code is blelow;
-----------------b.php----------------
<?php
function __autoload($class_name) {
 include_once $class_name . '.php';
}


$objref=new My("Good");
$objref->buff();
?>
-----------------------------------

----------My.php--------------
<?php
$obj=new My("Hello");
$obj->buff();


Class My{
      private $word;
      function __construct($getword){
      $this->word=$getword;
      }
      public function buff(){
      echo $this->word."<br />";
      }
}
?>
--------------------------------------

on website, first it execute My.php , then execute b.php

So it will show blelow;
Hello(when excute My.php)


Hello(when excute from b.php)
Good(when excute from b.php)



I do not need "Hello" twice


I would get

Hello(when excute My.php)
Good(when excute from b.php)

As you've already been told you should not really mix classes and procedural code in files. Put the My class into My.php, then have b.php and c.php where c.php contains the procedural code from My.php along with the __autoload from b.php.

I don't see why you insist on being able to "run" My.php. If it contains a class it should not be run as the main script. Ever!!

-Stut

--
http://stut.net/

--
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