note 24037 added to function.xml-set-object
| From: | chiefgeek@php.net | Date: | Mon, 05 Aug 2002 02:37:21 +0000 |
| Subject: | note 24037 added to function.xml-set-object | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-34280@lists.php.net to get a copy of this message | ||
Just adding a little note about my above written example. It needs some improvements.
Because PHP passes by VALUE by default, when you pass an array like this:
array($callback_handler, 'handler_method')
PHP makes a copy of the callback_handler object and uses the handler_method in the copy.
This is not an ideal situation for many reasons...which I will not get into here...but you should
have an idea by now.
The best way to fix this is to change a few things. In the function declaration change the parameter
from $callback_handler to &$callback_handler. So now your declaration should look like this
function set_callback_handler(&$callback_handler)
{
...
}
Now each time you reference $callback_handler change it to &$callback_handler. For example:
xml_set_element_handler(
$this->xml_parser,
array(&$callback_handler, 'start_element'),
array(&$callback_handler, 'close_Element' ));
This ensures that PHP will always use the same object.
--
http://www.php.net/manual/en/function.xml-set-object.php
http://master.php.net/manage/user-notes.php?action=edit+24037
http://master.php.net/manage/user-notes.php?action=delete+24037
http://master.php.net/manage/user-notes.php?action=reject+24037