title: how to save a php object to hashtable in php-extension?
body: <p>How to save a php object to hashtable and how to get a saved php obejct from hashtable in php-extension?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>//object_map has been init and alloc memory
  //return_value is the return var of PHP_FUNCTION
  
  zend_class_entry **class_ce,
  object_init_ex(return_value, *class_ce); //create object
  ioc_add_object_to_hash(name, return_value ); //save object
  
  //find in the hashtable
  if( zend_hash_find( object_map, name, sizeof(name), (void*)&amp;return_value ) == SUCCESS ){
  
      php_printf("return_value:%p, %p,type:%d\n", return_value,&amp;return_value, Z_TYPE_P(return_value));
      return 0;
  }
  
  //definition of ioc_add_object_to_hash
  int ioc_add_object_to_hash( const char *name, zval *obj )
  {
      if( !obj ){
          return -1;
      }
      if( !object_map ){
          return -1;
      }
      if( zend_hash_update( object_map, name, sizeof(name), obj, sizeof(*obj), NULL) == SUCCESS ){
          return 0;
      }
      return -1;
  }
  </code></pre>
  
  <p>PHP code:</p>
  
  <pre><code>   $filelist = array(
         "Foo" =&gt; realpath(__DIR__)."/Foo.php",
         "Bar" =&gt; realpath(__DIR__)."/Bar.php",
     );
  
     ioc::init( $filelist );
  
  
    var_dump(get_included_files());
  
    Bar::halo();
  
    $foo = ioc::make("Foo");
  
    echo $foo-&gt;get();
  
    $foo2 = ioc::make("Foo"); var_dump($foo2);
  </code></pre>
  
  <p>the $foo2 is NULL after second call ioc::make("Foo");</p>
  
  <p>all my code is push to <a href="https://github.com/longmon/php-ioc.git" rel="nofollow noreferrer">https://github.com/longmon/php-ioc.git</a>.</p>
  
  <p>Thank you!</p>