In php when using the destructor, does the code inside the destructor still have access to any methods and properties of the object?
1条回答 默认 最新
dongruo0909 2012-08-22 17:03关注Yes, you can access both methods and properties within a destructor, as demonstrated by this simple test-case:
class Foo { private $bar = 'member variable - '; function bar() { return 'function'; } function __destruct() { echo $this->bar; echo $this->bar(); } } $o = new Foo; unset( $o);Which prints:
member variable - function
See the PHP Docs on for deconstructors for more information, including their example of referencing a member variable from within the destructor.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报