为什么以下代码会导致分段错误?
<?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退出信号Segmentation fault(11).在一台服务器上,我正在运行Ubuntu 10.04,Apache 2,MysqL 5和PHP 5.3.2-1ubuntu4.9,而在另一台服务器上我正在运行Ubuntu 11.10,MysqL 5和PHP 5.3.6-13ubuntu3.3 .
2)这很奇怪,但是当我注释掉行$d2 = new DAO();或者行退出;,分段错误就消失了.
3)无论我在准备好的语句中选择哪个db表,都会发生分段错误
到底是怎么回事?我很沮丧.由于这种分段错误,我已经失去了一整天的时间.请…如果有人知道发生了什么,请告诉我
谢谢
看起来你在MysqLi模块中发现了一个错误!
原文链接:https://www.f2er.com/php/137392.html不过,不要指望它明天会被修复.找到一种方法来解决这个bug或尝试使用不同的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 ()