Arguments for __clone and __destruct

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
enoc22
Forum Commoner
Posts: 33
Joined: Wed Apr 01, 2009 12:45 pm

Arguments for __clone and __destruct

Post by enoc22 »

I didn't know exactly if i should post this here or in the theory bourd.
i am learning about OOP and classes and all that fun stuff
i know that with __construct() i can put a Variable i the parentheses as input and use it.
but it doesn't seem to work with __clone() or __destruct()
here's my code and me trying to put something in.

Code: Select all

<?
CLASS a{
    public $A=5;
    public $B=29;
    public $C=12;
    FUNCTION __construct(){
        echo"i'm the original<br>";
        echo $this->A . "<br>";
        echo $this->B . "<br>";
        echo $this->C . "<br>";
    }
    public FUNCTION __CLONE($data){
        $data++;
        echo $data;
        $totul=$this->A+$this->B/$this->C . "<br>";
        echo"i'm a clone of class a<br>";
        echo $totul;
    }
    FUNCTION __destruct(){
        $total=$this->A*$this->B*$this->C . "<br>";
        echo $total;
        echo"CLASS a closing down<br>";
 
    }
 
}
$a= new a();
 
 
?>
<h1 align="center>YOOHOO!</h1>
<?
$b= clone(1)$a;
?>
i get the following error
Fatal error: Method a::__clone() cannot accept any arguments in C:\.........\OBJ_base.php on line 18
If there is something i'm over looking let me know or if it's just a matter of looking. i tried the web couldn't see much.
any suggestions? is it possible to do what i am trying to do?
Anyways thanks

Oliver
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Arguments for __clone and __destruct

Post by requinix »

Cloning shouldn't modify data. By definition. It doesn't make sense for __clone to take arguments.
Same for a destructor. It destroys stuff.

So no, you can't pass arguments to __clone or __destruct. If you need something to vary and the functions can't do it themselves then you call a separate function beforehand.
enoc22
Forum Commoner
Posts: 33
Joined: Wed Apr 01, 2009 12:45 pm

Re: Arguments for __clone and __destruct

Post by enoc22 »

Thanks tasairis for your reply.
If i need to change things i will use a function now instead


Thanks
Oliver
Post Reply