php 扩展值打印不正确为什么?
我想通过参考发送对象。该对象代表一个
[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;
}
我在哪里错了? 谢谢! 等于
当我运行php test.php时,值得vor carr.l 155160836。为什么?我在哪里错了
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在代码的 php 部分中,
obj11
是一个未初始化的指针,它被传递给 Car2::method ((car2->method(*obj11));
) 。所以-In the php part of code,
obj11
is an uninitalized pointer and that is being passed to Car2::method ((car2->method(*obj11));
). So-