I was reading the book Extending and Embedding PHP and came across this line in C (with related structures):
typedef struct {
int sampleint;
char *samplestring;
} php_sample_globals;
int sample_globals_id;
(((php_sample_globals*)(*((void ***)tsrm_ls))[sample_globals_id - 1])->sampleint = 5
The author then writes:
“Don’t be concerned if you have trouble parsing that statement; it’s so well integrated into the PHPAPI that some developers never bother to learn how it works.”
I start to get lost around *((void ***)tsrm_ls)
Cast the variable
tsrm_lsas a pointer to a pointer to a pointer and then get what is pointed to (thus you end up with a pointer to a pointer)Looking at the rest of the code and assuming it is correct:
tsrm_lsis a pointer to an array of pointers tophp_sample_globalsstructures.This code looks at the
sample_globals_id-1index into that array finds the structure it points to and then sets thesampleintelement of that structure to 5