开发者

php extension value not correct printed why?

I want to send an object through reference. The object represents a class

[test.php]

$car= new Car();
$car->l=1000;

$car2 = new Car2();
$car2->method($car);

[php_cod.cc]

PHP_METHOD(Car2, method)
{
    Car2 *car;
    Car obj11;
    zend_class_entry ce2;

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



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

        //car2->reference(s);
        (car2->method(obj11));
    }

}

[开发者_开发问答test.cc]

void Car2::method(Car &carr)
{
    cout<<"IN THE REFERENCE CLASS"<<carr.l<<endl; 

}

Where am I wrong? THX! Appreciate

When I run php test.php the value vor carr.l is equal with 155160836. WHY? Where am I wrong


In the php part of code, obj11 is an uninitalized pointer and that is being passed to Car2::method ( (car2->method(*obj11)); ). So-

 cout<<"IN THE REFERENCE CLASS"<<carr.l<<endl; 
 // carr is a garbage reference and is causing the segmentation fault
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜