gpt4 book ai didi

php - PHP 中的段错误?

转载 作者:可可西里 更新时间:2023-11-01 12:36:33 25 4
gpt4 key购买 nike

为什么下面的代码会导致段错误?

<?php

$CNX = new mysqli('localhost','dbuser', 'dbpass', 'dbtest');

class DAO
{
var $stmt;

function DAO()
{
$this->stmt = $GLOBALS['CNX']->stmt_init();
}

function listing()
{
$this->stmt->prepare('SELECT * FROM any_table');
}
}

class Page
{
function go()
{
$d1 = new DAO();
$d2 = new DAO();
$d1->listing();
exit;
}
}

$tpl = new Page();
$tpl->go();
?>

附加说明

1) 我在两个不同的 LAMP 服务器上运行了这段代码,它们都在我的 error.log 文件中生成了类似 child pid somenumber exit signal Segmentation fault (11) 的错误。在一台服务器上,我运行的是 Ubuntu 10.04、Apache 2、Mysql 5 和 PHP 5.3.2-1ubuntu4.9,在另一台服务器上我运行的是 Ubuntu 11.10、Apache 2、mysql 5 和 PHP 5.3.6-13ubuntu3.3 .

2) 很奇怪,但是当我注释掉 $d2 = new DAO(); 行或 exit; 行时,段错误就消失了。

3)无论我在prepared statement中select哪个db表都会出现segmentation fault

这是怎么回事?我很沮丧。由于这个段错误,我浪费了一整天的时间。请...如果有人知道发生了什么,请告诉我

谢谢

最佳答案

看起来你在 mysqli 模块中发现了一个错误!

提交至https://bugs.php.net/

不过,不要指望它明天就能修好。找到解决该错误的方法或尝试使用不同的 PHP/mysqli 版本以查看是否可以解决问题。

作为引用,我也可以重现它,这是回溯。看起来在尝试关闭连接和清理时事情正在爆炸:

jon@jonx:~/tmp$ gdb `which php`
...
Reading symbols from /usr/bin/php...(no debugging symbols found)...done.
(gdb) run tmp.php
Starting program: /usr/bin/php tmp.php
[Thread debugging using libthread_db enabled]
[New Thread 0x7ffff3cb7700 (LWP 1028)]
[Thread 0x7ffff3cb7700 (LWP 1028) exited]

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff458ca25 in vio_peer_addr () from /usr/lib/libmysqlclient_r.so.16
(gdb) bt
#0 0x00007ffff458ca25 in vio_peer_addr () from /usr/lib/libmysqlclient_r.so.16
#1 0x00007ffff458d873 in net_real_write () from /usr/lib/libmysqlclient_r.so.16
#2 0x00007ffff458dd5b in net_flush () from /usr/lib/libmysqlclient_r.so.16
#3 0x00007ffff458df40 in net_write_command () from /usr/lib/libmysqlclient_r.so.16
#4 0x00007ffff458aa84 in cli_advanced_command () from /usr/lib/libmysqlclient_r.so.16
#5 0x00007ffff455c23c in mysql_stmt_close () from /usr/lib/libmysqlclient_r.so.16
#6 0x00007ffff42f3815 in ?? () from /usr/lib/php5/20090626/mysqli.so
#7 0x00007ffff42f38ca in ?? () from /usr/lib/php5/20090626/mysqli.so
#8 0x00000000006b6ad1 in zend_objects_store_del_ref_by_handle_ex ()
#9 0x00000000006b6af3 in zend_objects_store_del_ref ()
#10 0x0000000000683662 in _zval_ptr_dtor ()
#11 0x000000000069f313 in zend_hash_destroy ()
#12 0x00000000006b2ae9 in zend_object_std_dtor ()
#13 0x00000000006b2b09 in zend_objects_free_object_storage ()
#14 0x00000000006b663f in zend_objects_store_free_object_storage ()
#15 0x0000000000683c84 in ?? ()
#16 0x0000000000691cd5 in ?? ()
#17 0x000000000063eccf in php_request_shutdown ()
#18 0x000000000072c76c in ?? ()
#19 0x00007ffff55f5eff in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#20 0x0000000000428859 in _start ()

关于php - PHP 中的段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8542212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com