2 Questions Re: Anonymous Functions
| From: | Timothy Boronczyk | Date: | Mon, 09 Jun 2003 22:42:37 +0000 |
| Subject: | 2 Questions Re: Anonymous Functions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-150823@lists.php.net to get a copy of this message | ||
I'm extracting a list of items from an XML document using PHP. The desired
items are the attributes of different occurances of a specific element
within the document; the code will not need a callback for character data or
for closing tags.
$list = new Array();
function start_tag($p_id, $element, $attribs)
{
global $list;
if ($element = 'building')
$list[] = $attribs['address'];
return true;
}
//.. snip .. snip ..
xml_set_element_handler($parser, 'start_tag', create_function
('',''));
//.. snip .. snip ..
Two questions:
1. create_function ('',''); works just fine, but I was wondering if there
was a proper way to declare a void anonymous function?
2. If I were to place the parser related code within it's own function to
increase readability of the script, how would start_tag be rewritten as an
inline anonymous function? I've tried several ideas but I'm not sure how to
handle $location and it's change in scope.
Thanks in advance,
-Tim