Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
<?
class CxTest1{
function __construct()
{
echo __CLASS__.'::ctor()<br>';
}
function __destruct()
{
echo __CLASS__.'::dtor()<br>';
}
}
if(1){
$obj = new CxTest1();
}
echo 'Test<br>';
?>
Unfortunate, because I just encountered a problem which would best be solved using the intrinsic destruction of objects and relied only block scope to destroy objects...
But it appears this isn't the case...
Anyone know if this is a bug or issue they are looking into???
p.s-There is not point in me calling unset on the object to explicitly destroy the object...incase you are wondering
The object is constructed inside the IF *block* and therfore should destruct once we leave the IF block (or at least what I would expect, but it appears PHP doesn't support block scope)
However the object doesn't destruct until EOS, however objects do get destroyed on returning from functions...
Meh...no biggie...just an observation...it would have made for an interesting solution, but there are other ways
Well the other half of it... in any garbage collected languange destructors aren't called until the garbage collector runs, not immediately when the object is non referenceable. Thus you can't guess at scope from patterns of destructor invocation.
Hockey wrote:The object is constructed inside the IF *block* and therfore should destruct once we leave the IF block (or at least what I would expect, but it appears PHP doesn't support block scope)
Ok ... that qualifies as the absolutely craziest thing I have heard today.
Last edited by Christopher on Tue May 23, 2006 7:43 pm, edited 1 time in total.
if (1) {
$foo="Created"
}
// if block scoped $foo should not be accessible as foo was created within the block
echo isset($foo) ? "Not Blocked Scoped" : "Blocked Scope";
nielsene wrote:Well the other half of it... in any garbage collected languange destructors aren't called until the garbage collector runs, not immediately when the object is non referenceable. Thus you can't guess at scope from patterns of destructor invocation.
Hockey wrote:The object is constructed inside the IF *block* and therfore should destruct once we leave the IF block (or at least what I would expect, but it appears PHP doesn't support block scope)
Ok ... that qualifies as the absolutely craziest thing I have heard today.
I don't think block scope is crazy, regardless of its actual usefulnes. It is that you need scope operators like my or our to do that and there aren't any in PHP.
if (1) {
$foo="Created"
}
// if block scoped $foo should not be accessible as foo was created within the block
echo isset($foo) ? "Not Blocked Scoped" : "Blocked Scope";
Doesn't Java have garbage collection? Much like C#? If so doesn't that go against what you just told GC languages don't call constructors until after cleanup? Makes sense, but I can't see that being a requirement...
just not a good way to test for it...
What do you mean?
Without going into a lot of details, suffice it to say, I clearly understood the implications of relying on dtor() being called as it went out of scope...
I was not trying to test for anything, but rather constructing a META language using what I thought was intrinsic OO functionality...
Ever heard of Spirit? Thats what I was going after...sorta...but emulating a META language to represent a structured document (HTML for instance) therefore dtor() at script quittin' time won't work...
arborint wrote:I don't think block scope is crazy, regardless of its actual usefulnes. It is that you need scope operators like my or our to do that and there aren't any in PHP.
I have never heard of scope operators like *my* or *our*
How would they play a role in what I was trying to do?
I simply needed an object to destruct like what I am accustomed too tis all