如何将zval *转换为对象?

时间:2011-09-15 08:13:36

标签: php c++ php-extension

我有:

PHP_METHOD(Car, cls_ref)
{
    Car *car;
    //Car2 *obj11;
    Car2 *car2;
    zval* obj11;
    zend_class_entry ce2 = zend_fetch_class("Car2", sizeof("Car2")-1, ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC);


     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &obj11,ce2) == FAILURE) {
        RETURN_NULL();
    }

    car_object *obj = (car_object *)zend_object_store_get_object(
        getThis() TSRMLS_CC);
  /*  car2_object *objj = (car2_object *)zend_object_store_get_object(
        getThis() TSRMLS_CC);
       car2=(objj->car2);
    */  
    car = obj->car;
    if (car != NULL) {
        //cout<<"in car 2 ref"<<endl;

        //car2->reference(s);
    //  (car->cls_ref((Car2&)car2));
    car->cls_ref((Car2&)obj11);
    }

}

where void Car::cls_ref(Car2 &obj){...}
我解决这个问题。我有错误:

  

错误:初始化时无法将'Car2 *'转换为'zval *'       /home/vehicles.cc:191:错误:从'zend_class_entry *'转换为非标量类型'zend_class_entry'请求`(错误发生在我初始化obj11和ce2 = ..)

1 个答案:

答案 0 :(得分:1)

使用API​​ convert_to_object_ex(value)将zval转换为object。这里的值是** zval类型。

-Gaurav