__destruct() not called ! we shot us in the foot try the script
am 25.08.2009 01:40:13 von Ralph Deffke
well I would call this an error in the first view , and some of u where
right! and the stuff with the refernce counter seems to be right as well.
however I can't see a reason for it as 5.x works through refernces. so
unsetting a REFERENCE to the object does not destroy it.
How to destroy the object then?
abstract class a {
public function __construct(){
echo "constructing....
";
}
public function __destruct(){
echo "destructing....
";
}
}
class b extends a{
public function doSomething(){
echo "I'm doing ...but the reference c to the object is unset()
";
}
}
$c = new b();
$d = $c ; // works
$f[] = $c ; // works
class e {
public static $m;
public static function setM( $m ){
self::$m = $m;
}
}
$o = new e();
e::setM( $c ); // works
echo "unsetting ...
";
unset( $c );
$d->doSomething();
echo "script ending now ...
";
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: __destruct() not called ! we shot us in the foot try thescript
am 25.08.2009 02:07:16 von List Manager
Ralph Deffke wrote:
Sorry to bring it to this thread, but could you respond to Ashley in the
"[PHP] wierd behavior on parsing css with no php included" thread.
We would like the solution place in the archives to future visitor benefit.
Thanks
Jim
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: __destruct() not called ! we shot us in the foot try the
am 25.08.2009 23:15:33 von Martin Scotta
--00163646d5a0bfb9980471fdd578
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
__destruct is called only when the object is detroyed.
The object is destroyed only when there is no references to it.
error_reporting( E_ALL | E_STRICT );
header( 'Content-Type: text/plain' );
class Foo
{
function __destruct()
{
echo __METHOD__, PHP_EOL;
}
}
$a = new Foo;
$b = $a; # <<<< try the script without this line or commented
unset( $a ); # no destructor called
echo '--', PHP_EOL;
unset( $b ); # destructor called!
On Mon, Aug 24, 2009 at 8:40 PM, Ralph Deffke wrote:
>
> well I would call this an error in the first view , and some of u where
> right! and the stuff with the refernce counter seems to be right as well.
>
> however I can't see a reason for it as 5.x works through refernces. so
> unsetting a REFERENCE to the object does not destroy it.
>
> How to destroy the object then?
>
>
>
>
> abstract class a {
> public function __construct(){
> echo "constructing....
";
> }
> public function __destruct(){
> echo "destructing....
";
> }
> }
>
> class b extends a{
>
> public function doSomething(){
> echo "I'm doing ...but the reference c to the object is unset()
";
> }
>
> }
>
> $c = new b();
>
> $d = $c ; // works
> $f[] = $c ; // works
>
> class e {
> public static $m;
>
> public static function setM( $m ){
> self::$m = $m;
> }
> }
>
> $o = new e();
> e::setM( $c ); // works
>
> echo "unsetting ...
";
> unset( $c );
>
> $d->doSomething();
>
> echo "script ending now ...
";
>
> ?>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Martin Scotta
--00163646d5a0bfb9980471fdd578--