|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-11-16 23:06 UTC] tater at potatoe dot com
Description:
------------
a switch() statement testing a string offset, like
'switch($string{0})', crashes after executing the
matching case or default block. this only happens
if there is at least one case. workarounds: assign
offset to another variable first, or put it in
quotes like "{$string{0}}".
This breaks a lot of PEAR code, btw.
Reproduce code:
---------------
$x = 'abc';
switch ($x{0}) { default: print "default - works\n"; }
switch ($x{0}) { case 'a': print "case 'a' - bus error\n"; }
print "done\n";
Expected result:
----------------
default - works
case 'a' - bus error
done
Actual result:
--------------
default - works
case 'a' - bus error
Bus error
--------------------
backtrace:
(gdb) run bug.php
Starting program: /usr/local/book/php/bin/php bug.php
[Switching to process 5410 thread 0xb03]
Reading symbols for shared libraries . done
Reading symbols for shared libraries ............ done
default - works
case 'a' - bus error
Program received signal EXC_BAD_ACCESS, Could not access memory.
0x00229f8c in _zval_dtor (zvalue=0xbb4c10, __zend_filename=0x2c2a24 "/Users/tater/book/php-src/Zend/zend_execute.c", __zend_lineno=203) at /Users/tater/book/php-src/Zend/zend_variables.c:44
44 CHECK_ZVAL_STRING_REL(zvalue);
(gdb)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 08:00:01 2025 UTC |
This still crashes, here's the backtrace: [Switching to Thread 16384 (LWP 12818)] 0x0831ac74 in _zval_ptr_dtor (zval_ptr=0xbfffd680, __zend_filename=0x8571ae0 "/usr/src/web/php/php5/Zend/zend_execute.c", __zend_lineno=197) at /usr/src/web/php/php5/Zend/zend_execute_API.c:352 352 (*zval_ptr)->refcount--; (gdb) bt #0 0x0831ac74 in _zval_ptr_dtor (zval_ptr=0xbfffd680, __zend_filename=0x8571ae0 "/usr/src/web/php/php5/Zend/zend_execute.c", __zend_lineno=197) at /usr/src/web/php/php5/Zend/zend_execute_API.c:352 #1 0x083514f7 in zend_switch_free (opline=0x40e48e80, Ts=0xbfffd610) at /usr/src/web/php/php5/Zend/zend_execute.c:197 #2 0x0834d76a in zend_switch_free_handler (execute_data=0xbfffd7a0, op_array=0x40e488b4) at /usr/src/web/php/php5/Zend/zend_execute.c:3070 #3 0x083481e9 in execute (op_array=0x40e488b4) at /usr/src/web/php/php5/Zend/zend_execute.c:1269 #4 0x08326c78 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/web/php/php5/Zend/zend.c:1016 #5 0x082e585b in php_execute_script (primary_file=0xbffffba0) at /usr/src/web/php/php5/main/main.c:1625 #6 0x083602e3 in main (argc=2, argv=0xbffffc34) at /usr/src/web/php/php5/sapi/cli/php_cli.c:910