PHP 8.5.0 Alpha 2 available for testing

Voting

: two plus one?
(Example: nine)

The Note You're Voting On

chiefgeek at ecodedesign.com
22 years ago
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.

<< Back to user notes page

To Top