运行以下 PHP 代码时,我得到一个 "Segmentation fault: 11" :
$pattern = '#^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$#';
$horas = "2012-05-15 11:23:56";
echo filter_var($horas, FILTER_VALIDATE_REGEXP, array("options" => array('regexp' => $pattern))) ? "1" : "2";
如果我使用较短的正则表达式,则不会出现任何分段错误:
$pattern = '#^([\+-]?\d*)$#';
$horas = "2012-05-15 11:23:56";
echo filter_var($horas, FILTER_VALIDATE_REGEXP, array("options" => array('regexp' => $pattern))) ? "1" : "2";
在这种情况下,值为“2”。
我决定使用 strace(或 dtruss,因为我使用的是 OSX)并比较不同正则表达式的输出。虽然我不知道从哪里开始,但我意识到第一个脚本停在这里:
open("/opt/local/lib/libmemcached.9.dylib\0", 0x0, 0x0) = 3 0
pread(0x3, "\317\372\355\376\a\0", 0x1000, 0x0) = 4096 0
mmap(0x103532000, 0x24000, 0x5, 0x12, 0x3, 0x100001F) = 0x3532000 0
mmap(0x103556000, 0x1000, 0x3, 0x12, 0x3, 0x100001F) = 0x3556000 0
mmap(0x103557000, 0x15098, 0x1, 0x12, 0x3, 0x100001F) = 0x3557000 0
close(0x3) = 0 0
stat64("/opt/local/lib/libsasl2.2.dylib\0", 0x7FFF61CDD430, 0x7FFF61CDE2B0) = 0 0
open("/opt/local/lib/libsasl2.2.dylib\0", 0x0, 0x0) = 3 0
pread(0x3, "\317\372\355\376\a\0", 0x1000, 0x0) = 4096 0
mmap(0x10356D000, 0x14000, 0x5, 0x12, 0x3, 0x100001F) = 0x356D000 0
mmap(0x103581000, 0x1000, 0x3, 0x12, 0x3, 0x100001F) = 0x3581000 0
mmap(0x103582000, 0x3848, 0x1, 0x12, 0x3, 0x100001F) = 0x3582000 0
close(0x3) = 0 0
__sysctl(0x7FFF61CDE14C, 0x2, 0x7FFF61CDE138) = 0 0
我不确定这是否有帮助,或者它是否与 libsasl 有关。我最近使用 macports 升级了 php5、apache2 和其他一些软件包。此代码用于在升级之前工作。这是 php -version 的输出:
PHP 5.3.12 (cli) (built: May 11 2012 14:31:01) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.0,版权所有 (c) 2002-2012,Derick Rethans 和 Suhosin v0.9.33,版权 (c) 2007-2012,SektionEins GmbH
先感谢您。