Re: unset( $anobject) does not invoce __destruct()

Re: unset( $anobject) does not invoce __destruct()

am 24.08.2009 20:22:42 von hack988 hack988

see http://cn.php.net/manual/en/language.oop5.abstract.php
PHP 5 introduces abstract classes and methods. It is not allowed to
create an instance of a class that has been defined as abstract. Any
class that contains at least one abstract method must also be
abstract. Methods defined as abstract simply declare the method's
signature they cannot define the implementation.

You make misconception understand for abstract class,:(, correct code is:
abstract class a {
abstract public function __construct(){

}
abstract public function __destruct(){

}
}

class b extends a{
public function __construct(){
echo "constructing....
";
}
public function __destruct(){
echo "destructing....
";
}
}

$c = new b();
unset($c);

if you want to make it work correctly that you want,plase change code to follow
class c {
public function __construct(){
echo "constructing....
";
}
public function __destruct(){
echo "destructing....
";
}
}

class d extends c{

}
$e = new d();
unset($e);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: unset( $anobject) does not invoce __destruct()

am 24.08.2009 21:46:56 von Ralph Deffke

I dont agree, and as u see in my snipped code it works fine.

in an abstract class u can define an implementation to define some basic
things a overwriting function in an extending class has to take care of as
well.

this includes specialy magic functions.

thats what they are made for. may be you talk about interfaces ?

"hack988 hack988" wrote in message
news:4d03254c0908241122r5b6d1c3csc06ec475a0797218@mail.gmail .com...
> see http://cn.php.net/manual/en/language.oop5.abstract.php
> PHP 5 introduces abstract classes and methods. It is not allowed to
> create an instance of a class that has been defined as abstract. Any
> class that contains at least one abstract method must also be
> abstract. Methods defined as abstract simply declare the method's
> signature they cannot define the implementation.
>
> You make misconception understand for abstract class,:(, correct code is:
> abstract class a {
> abstract public function __construct(){
>
> }
> abstract public function __destruct(){
>
> }
> }
>
> class b extends a{
> public function __construct(){
> echo "constructing....
";
> }
> public function __destruct(){
> echo "destructing....
";
> }
> }
>
> $c = new b();
> unset($c);
>
> if you want to make it work correctly that you want,plase change code to
follow
> class c {
> public function __construct(){
> echo "constructing....
";
> }
> public function __destruct(){
> echo "destructing....
";
> }
> }
>
> class d extends c{
>
> }
> $e = new d();
> unset($e);



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php