note 95569 added to language.oop5.decon
| From: | JonathonHibbard at osu1 dot php dot net | Date: | Sun, 10 Jan 2010 00:32:14 +0000 |
| Subject: | note 95569 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164819@lists.php.net to get a copy of this message | ||
Please be aware of when using __destruct() in which you are unsetting variables...
Consider the following code:
<?php
class my_class {
public $error_reporting = false;
function __construct($error_reporting = false) {
$this->error_reporting = $error_reporting;
}
function __destruct() {
if($this->error_reporting === true) $this->show_report();
unset($this->error_reporting);
}
?>
The above will result in an error:
Notice: Undefined property: my_class::$error_reporting in my_class.php on line 10
It appears as though the variable will be unset BEFORE it actually can execute the if statement.
Removing the unset will fix this. It's not needed anyways as PHP will release everything
anyways, but just in case you run across this, you know why ;)
----
Server IP: 69.147.83.197
Probable Submitter: 75.186.62.40
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- https://master.php.net/note/edit/95569
Del: integrated -- https://master.php.net/note/delete/95569/integrated
Del: useless -- https://master.php.net/note/delete/95569/useless
Del: bad code -- https://master.php.net/note/delete/95569/bad+code
Del: spam -- https://master.php.net/note/delete/95569/spam
Del: non-english -- https://master.php.net/note/delete/95569/non-english
Del: in docs -- https://master.php.net/note/delete/95569/in+docs
Del: other reasons-- https://master.php.net/note/delete/95569
Reject -- https://master.php.net/note/reject/95569
Search -- https://master.php.net/manage/user-notes.php