[TYPO3-mvc] Question about Filter-Objects
Martin Kutschker
masi-no at spam-typo3.org
Sat Mar 13 22:55:00 CET 2010
Franz Koch schrieb:
> Just a note: a simple "unset($object)" won't work as long as there are
> still references to that object (which most likely are if extbase
> created/injected a object),
Right. An object exists as long as at least one reference to it exists. If the last one is removed
the destructor is called and PHP will free the memory.
> so according to some comments I found on the
> net you first have to overwrite the object with NULL and then delete it:
> $object = NULL; unset($object);
And why should this destroy the object? If $object is the only reference to your object then the
unset is not needed. Try this code:
<?php
class X {
function __destruct() {
echo "Ah! I'm dying.\n";
}
}
$x = new X();
echo "Step 1\n";
$x = NULL;
echo "Step 2\n";
unset($x);
echo "Step 3\n";
?>
You will see that the destructor is called after step 1 (the assignment).
Looks like you have to ask the persistence framework explicitly to release the object from automatic
persistence. Steffen's use case looks a bit strange to me, but I guess there can be other reasons
why you may want to that the current state of an entitty is not persisted.
Masi
More information about the TYPO3-project-typo3v4mvc
mailing list