title: Porting a php5 module to php 7 and zend_string issues when compiling
body: <p>I'm porting a php5 tot php7, but don't understand how to correctly use zend_string since it gives me errors when compiling. I followed the <a href="https://wiki.php.net/phpng-upgrading" rel="nofollow noreferrer">phpng guide</a> on the changes in php7. Most functions i could port easily, but this function is giving me a headache.</p>
  
  <p>The php5 version of the module looks like this:</p>
  
  <pre><code>PHP_FUNCTION(swe_houses)
  {
  char *arg = NULL;
  int hsys_len, rc;
  char *hsys = NULL;
  double tjd_ut, geolat, geolon;
  double cusps[37], ascmc[10]; 
  int i, houses;
  zval *cusps_arr, *ascmc_arr;
  
  if(ZEND_NUM_ARGS() != 4) WRONG_PARAM_COUNT;
  
  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ddds",
          &amp;tjd_ut, &amp;geolat, &amp;geolon, &amp;hsys, &amp;hsys_len) == FAILURE) {
      return;
  }
  if (hsys_len &lt; 1)
      return;
  
  rc = swe_houses(tjd_ut, geolat, geolon, hsys[0], cusps, ascmc);
  
  /* create 2 index array, and 1 assoc array */
  array_init(return_value);
  
  MAKE_STD_ZVAL(cusps_arr);
  array_init(cusps_arr);
  
  if (hsys[0] == 'G')
      houses = 37;
  else
      houses = 13;
  
  for(i = 0; i &lt; houses; i++)
      add_index_double(cusps_arr, i, cusps[i]);
  
  MAKE_STD_ZVAL(ascmc_arr);
  array_init(ascmc_arr);
  for(i = 0; i &lt; 10; i++)
      add_index_double(ascmc_arr, i, ascmc[i]);
  
  add_assoc_zval(return_value, "cusps", cusps_arr);
  add_assoc_zval(return_value, "ascmc", ascmc_arr);
  add_assoc_long(return_value, "rc", rc);
  }
  </code></pre>
  
  <p>So the guide says i need to replace "char *hsys" into "zend_string *hsys = null". And replaced "MAKE_STD_ZVAL" functions to "ZVAL_NEW_ARR". In the zend_parse_parameters function i changed the "s" parameter to "S".</p>
  
  <p>So eventually i changed the code to look like this:</p>
  
  <pre><code>PHP_FUNCTION(swe_houses)
  {
  zend_string *arg = NULL;
  size_t hsys_len, rc;
  zend_string *hsys = NULL;
  double tjd_ut, geolat, geolon;
  double cusps[37], ascmc[10]; 
  size_t i, houses;
  zval *cusps_arr, *ascmc_arr;
  
  if(ZEND_NUM_ARGS() != 4) WRONG_PARAM_COUNT;
  
  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dddS",
          &amp;tjd_ut, &amp;geolat, &amp;geolon, &amp;hsys, &amp;hsys_len) == FAILURE) {
      return;
  }
  if (hsys_len &lt; 1)
      return;
  
  rc = swe_houses(tjd_ut, geolat, geolon, hsys[0], cusps, ascmc);
  
  /* create 2 index array, and 1 assoc array */
  array_init(return_value);
  
  /*******************************/
  /*      removed for php 7      */
  /*   MAKE_STD_ZVAL(cusps_arr); */
  /*******************************/
  
  ZVAL_NEW_ARR(cusps_arr);
  array_init(cusps_arr);
  
  if (hsys[0] == 'G')
      houses = 37;
  else
      houses = 13;
  
  for(i = 0; i &lt; houses; i++)
      add_index_double(cusps_arr, i, cusps[i]);
  
  /*******************************/
  /*      removed for php 7      */   
  /*    MAKE_STD_ZVAL(ascmc_arr); */
  /*******************************/
  
  ZVAL_NEW_ARR(ascmc_arr);
  array_init(ascmc_arr);
  
  
  for(i = 0; i &lt; 10; i++)
      add_index_double(ascmc_arr, i, ascmc[i]);
  
  add_assoc_zval(return_value, "cusps", cusps_arr);
  add_assoc_zval(return_value, "ascmc", ascmc_arr);
  add_assoc_long(return_value, "rc", rc);
  }
  </code></pre>
  
  <p>But on compilling it gives me the following errors:</p>
  
  <pre><code>/home/hermes/php-sweph/latest/php-sweph/sweph.c:926:42: error:   
  incompatible type for argument 4 of ‘swe_houses’
  rc = swe_houses(tjd_ut, geolat, geolon, hsys[0], cusps, ascmc);
                                        ^
  In file included from /home/hermes/php-sweph/latest/php- 
  sweph/sweph.c:23:0:
  
  /usr/local/include/swephexp.h:742:16: note: expected ‘int’ but argument is       
  
  of type ‘zend_string {aka struct _zend_string}’
  ext_def( int ) swe_houses(
              ^
  /home/hermes/php-sweph/latest/php-sweph/sweph.c:939:14: error: invalid    
  operands to binary == (have ‘zend_string {aka struct _zend_string}’ and        
  ‘int’)
  if (hsys[0] == 'G')
  </code></pre>