The online racing simulator
Storing in a "table" in PHP?
2
(31 posts, started )
Quote from NotAnIllusion :Ok, that I can understand. A plot is beginning to emerge

So?:

<?php 
php

class user {
    var 
$pname;
    var 
$uname;
    var 
$ucid;
    var 
$plid;
    function 
__construct() {
        echo 
'Hi';
    }
    function 
__destruct() {
        echo 
'Bye';
    }
}

$user = new user();
echo 
'doSomething';
unset(
$user);
echo 
'oneLastThing';

?>

The plot is that basically I don't bother to clean up I removed all calls to the destructor, now it triggers only when I unset() the guest object copy created in a foreach() loop. I suspect the reason the original guest object in the $guests array isn't being destroyed when I do

<?php 
unset($guests[$guest->uname]);
?>

because that $guest is actually a copy of the guest object I'm trying to destroy

<?php 
php

    
/* Class */
    
class user {
        var 
$pname;
        var 
$uname;
        var 
$ucid;
        var 
$plid;
        function 
__construct($pname$uname$ucid$plid) {
            
$this->pname $pname;
            
$this->uname $uname;
            
$this->ucid $ucid;
            
$this->plid $plid;
            echo 
"Hello {$this->uname}\n";
        }
        function 
__destruct() {
            echo 
"Bye {$this->uname}\n";
        }
    }

    class 
engine {
        var 
$users = array();
    }

    
/* Engine Event(s) */
    
function eeClientConnects ($pname$uname$ucid$plid) {
        global 
$engine;
        
$engine->users[$uname] = new user($pname$uname$ucid$plid);
    }
    function 
eeClientDisconnections ($uname) {
        global 
$engine;
        unset(
$engine->users[$uname]);
    }

    
/* Defines */
    
$engine = new engine();

    
// Run The Program :)
    
eeClientConnects('(EAGLE)Dygear''Dygear'01);
    
eeClientConnects('FPL^filur''filur'01);
    
eeClientDisconnections('Dygear');
    
eeClientConnects('^1Pringles''NotAnIllusion'01);
    
eeClientDisconnections('filur');
    
eeClientDisconnections('NotAnIllusion');

?>

Hello Dygear
Hello filur
Bye Dygear
Hello NotAnIllusion
Bye filur
Bye NotAnIllusion

Yes, that's the way it's supposed to work. I also demonstrated to myself that what I'm trying to do should be working, which narrows down my problem to not having cleared all the references. Fortunately, it's just a test to see if I can do it, rather than an attempt to do it properly (which is up next)


<?php 
php

class foo {
    var 
$a;
    var 
$b;
    var 
$c;

    function 
__construct($a$b$c) {
        foreach(
get_class_vars(get_class($this)) as $var => $val) {
            
$this->$var = $$var;
        }
        echo 
"\r\nI'm alive!\r\n";
    }
    
    function 
__destruct() {
        echo 
"\r\nI'm dying..\r\n";
    }
}

$bar = array();

$bar['d'] = new foo('d''e'1);
$bar['f'] = new foo('f''g'2);
$bar['h'] = new foo('h''i'3);
$bar['j'] = new foo('j''k'4);

foreach(
$bar as $objcopy) {
    if(
$objcopy->== 3) {
        unset(
$bar[$objcopy->a]);
    }
}

echo 
"\r\n--- Normal termination ---\r\n";

?>

Output
I'm alive!
I'm alive!
I'm alive!
I'm alive!
I'm dying..

--- Normal termination ---
I'm dying..
I'm dying..
I'm dying..

Quote from NotAnIllusion :Yes, that's the way it's supposed to work. I also demonstrated to myself that what I'm trying to do should be working, which narrows down my problem to not having cleared all the references. Fortunately, it's just a test to see if I can do it, rather than an attempt to do it properly (which is up next)

Good luck mate, shoot a message and I'll see what I can come up with for ya if you need a hand. As for everyone else, I hope you enjoyed the examples.
Immensely
2

Storing in a "table" in PHP?
(31 posts, started )
FGED GREDG RDFGDR GSFDG