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->c == 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..