I sincerely hope someone might take a moment to help me grok pointers. I have some source code that I'm trying to understand, namely the json.c file that underlies PHP's JSON extension.
When one calls the json_encode function within a PHP script, some magic happens wherein the zend engine parses a ZVAL object and a LONG, creates a char pointer, and some other vars, and then feeds them to a function, php_json_encode which, in turn, passes the zval function such as json_encode_array.
Now there are a lot of pointers (and macros) flying in this code sample which is confusing to me as my C/C++ is extremely rusty. I'm trying to understand a few things:
1) The call to zend_parse_parameters on line 565 passes the address-of value of parameter because we want the zend_parse_parameters function to change this value, right?
2) The first call to php_json_encode (on line 559) passes the var parameter (a zval*) directly to the function. Am I correct in understanding that parameter contains the memory address of a zval object?
3) The php_json_encode function receives the parameter as val, a pointer to a zval object. If this object is an array or object, then its address passed on to the json_encode_array function on line 475. Why use the & (address-of) operator here? Is this just sloppy and/or random use of pointers and & operators or is it necessary for some reason? Keep in mind the json_encode_array function does not need to alter the contents of val.
Any help would be much appreciated. I'm hoping to contribute to another PECL extension I'm working on. I used to know pointers reasonably well, but that was a very long time ago. Any tips, heuristic guidance, advice, or pointers (har har) would be much appreciated.