Bug #55416 [Com]: array_map() throws PHP warning if the callback throws an exception

2012-02-12 Thread harvey dot robin at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=55416&edit=1

 ID: 55416
 Comment by: harvey dot robin at gmail dot com
 Reported by:roan dot kattouw at gmail dot com
 Summary:array_map() throws PHP warning if the callback
 throws an exception
 Status: Open
 Type:   Bug
 Package:Arrays related
 Operating System:   Ubuntu Natty
 PHP Version:5.4.0alpha3
 Block user comment: N
 Private report: N

 New Comment:

I've just come across this too and I'm really surprised at this inconsistent 
behavior, for me the question isn't "what kind of situation needs throw a 
exception in map function" but "why would the map function behave differently 
to any other situation".  If you change array_map to array_walk in the original 
example then the exception propagates upward, as expected.

At the very least, I'd expect to see a note on the PHP manual page warning 
users that exceptions work differently for the callback parameter to array_walk.


Previous Comments:

[2011-08-16 16:20:17] mah at everybody dot org

http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94433 has Roan's actual 
use case.


[2011-08-15 09:35:40] roan dot kattouw at gmail dot com

Basically what I'm doing is

implode("\n", array_map('readStyleFile', $files)

where $files is an array of file names, and readStyleFile() can throw an 
exception if something is wrong (in this case it's if the file doesn't exist, 
but other cases are imaginable). This exception then propagates up a few levels 
and is caught and handled. Throwing an exception from inside the map callback 
works just fine: it stops the callback, stops array_map(), propagates up to the 
caller of array_map(), then works its way up the call stack like any other 
exception. The only issue is that warning that won't go away.


[2011-08-15 08:54:02] larue...@php.net

I was wondering what kind of situation needs throw a exception in map function?

and why doing that? thanks


[2011-08-13 20:40:11] roan dot kattouw at gmail dot com

Something I forgot to mention in the original report:

Using @array_map(...) suppresses the warning. However, it also suppresses any 
other notices or warnings that might happen in the callback. That's why I put 
the $foo = $bar['baz']; bit in barf(): if you use @array_map, the "Undefined 
variable" notice, which is legitimate, goes away as well.

More generally, @ is kind of a blunt instrument that often suppresses more than 
you expect it to, masking mistakes.


[2011-08-13 20:32:50] roan dot kattouw at gmail dot com

The attached patch fixes this by not throwing the warning if EG(exception) is 
not NULL. IMO the warning should be removed completely (because it's 
superfluous, and I don't see offhand how it can be triggered other than by an 
exception, but I don't know PHP core at all), but it's easy to tweak my patch 
into doing that instead; this patch is just the minimal solution.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=55416


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=55416&edit=1


#39151 [NEW]: Parse error in recursiveiteratoriterator.php

2006-10-13 Thread harvey dot robin at gmail dot com
From: harvey dot robin at gmail dot com
Operating system: Linux, Ubuntu
PHP version:  5.2.0RC5
PHP Bug Type: SPL related
Bug description:  Parse error in recursiveiteratoriterator.php

Description:

Hi,

I noticed a parse error in the file
ext/spl/internal/recursiveiteratoriterator.inc.  The same error is in the
web cvs view here:
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/internal/recursiveiteratoriterator.inc?view=markup

The error is on line 220, or 152, depending on whether there are any
comments in it.

Many thanks,

Robin Harvey

Reproduce code:
---
php -l ext/spl/internal/recursiveiteratoriterator.inc

Actual result:
--
Parse error: syntax error, unexpected T_VARIABLE in
ext/spl/internal/recursiveiteratoriterator.inc on line 220

-- 
Edit bug report at http://bugs.php.net/?id=39151&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39151&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39151&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39151&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39151&r=fixedcvs
Fixed in release: 
http://bugs.php.net/fix.php?id=39151&r=alreadyfixed
Need backtrace:   http://bugs.php.net/fix.php?id=39151&r=needtrace
Need Reproduce Script:http://bugs.php.net/fix.php?id=39151&r=needscript
Try newer version:http://bugs.php.net/fix.php?id=39151&r=oldversion
Not developer issue:  http://bugs.php.net/fix.php?id=39151&r=support
Expected behavior:http://bugs.php.net/fix.php?id=39151&r=notwrong
Not enough info:  
http://bugs.php.net/fix.php?id=39151&r=notenoughinfo
Submitted twice:  
http://bugs.php.net/fix.php?id=39151&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39151&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39151&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39151&r=dst
IIS Stability:http://bugs.php.net/fix.php?id=39151&r=isapi
Install GNU Sed:  http://bugs.php.net/fix.php?id=39151&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39151&r=float
No Zend Extensions:   http://bugs.php.net/fix.php?id=39151&r=nozend
MySQL Configuration Error:http://bugs.php.net/fix.php?id=39151&r=mysqlcfg


#41086 [NEW]: Seg fault and "corrupted double-linked list" with xslt warning

2007-04-14 Thread harvey dot robin at gmail dot com
From: harvey dot robin at gmail dot com
Operating system: Ubuntu feisty
PHP version:  5CVS-2007-04-14 (snap)
PHP Bug Type: XSLT related
Bug description:  Seg fault and "corrupted double-linked list" with xslt warning

Description:

Running a complex stylesheet (possibly with errors, certainly produces
warnings) results in a segmentation fault or a "corrupted double-linked
list"  The stylesheet uses exslt, and the dom it's parsing over is created
with the flags LIBXML_NOENT|LIBXML_DTDLOAD|LIBXML_DTDATTR.  The code also
uses a custom stream handler in conjunction with the xpath document
function.

When you run the tests below, there are a couple of warnings produced
before the crash, one is "XSLTProcessor::transformToXml(): Invalid type"
and the other is "XSLTProcessor::transformToXml(): xmlXPathCompiledEval: 4
objects left on the stack."  I've met these warnings before, but they have
never resulted in a crash.

Reproduce code:
---
The code needed to reproduce the error is available on the subversion
server of my project.  To produce the crash, do:

*> svn checkout http://taltastic.googlecode.com/svn/trunk/ -r 42
taltastic
*> cd taltastic/test
*> php test.php

This produces the double linked list fault on my system, to produce the
segmentation fault error you have to edit the test.php file and change the
$templ variable to load from "test.xml" instead of "test.html".

Here is my configure line:
[EMAIL PROTECTED]:~/libs/php5.2-CVS2$ cat config.nice 
#! /bin/sh
#
# Created by configure

'./configure' \
'--disable-cgi' \
'--enable-cli' \
'--with-zlib' \
'--with-bz2' \
'--with-gd' \
'--enable-gd-native-ttf' \
'--enable-mbstring' \
'--with-mcrypt' \
'--with-pdo-pgsql' \
'--disable-session' \
'--enable-sockets' \
'--with-xsl' \
'--enable-soap' \
'--enable-debug' \
"$@"

Expected result:

Expect to see an html document echoed to the screen.


Actual result:
--
...This one with the code as-is, using "test.html"...

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 47983451902976 (LWP 29653)]
0x2ba402eb738b in xmlXPathNodeSetAddUnique () from
/usr/lib/libxml2.so.2
(gdb) bt
#0  0x2ba402eb738b in xmlXPathNodeSetAddUnique () from
/usr/lib/libxml2.so.2
#1  0x2ba402eb78f5 in ?? () from /usr/lib/libxml2.so.2
#2  0x2ba402ec2b27 in ?? () from /usr/lib/libxml2.so.2
#3  0x2ba402ec2f74 in ?? () from /usr/lib/libxml2.so.2
#4  0x2ba402ec2948 in ?? () from /usr/lib/libxml2.so.2
#5  0x2ba402ec413e in ?? () from /usr/lib/libxml2.so.2
#6  0x2ba402ec8447 in ?? () from /usr/lib/libxml2.so.2
#7  0x2ba402ec8619 in xmlXPathCompiledEval () from
/usr/lib/libxml2.so.2
#8  0x2ba402c1acc2 in xsltEvalXPathPredicate () from
/usr/lib/libxslt.so.1
#9  0x2ba402c16714 in ?? () from /usr/lib/libxslt.so.1
#10 0x2ba402c17670 in xsltGetTemplate () from /usr/lib/libxslt.so.1
#11 0x2ba402c2be52 in xsltProcessOneNode () from
/usr/lib/libxslt.so.1
#12 0x2ba402c2caea in xsltApplyTemplates () from
/usr/lib/libxslt.so.1
#13 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#14 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#15 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#16 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#17 0x2ba402c2b6be in ?? () from /usr/lib/libxslt.so.1
#18 0x2ba402c2bbca in xsltCallTemplate () from /usr/lib/libxslt.so.1
#19 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#20 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#21 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#22 0x2ba402c2b6be in ?? () from /usr/lib/libxslt.so.1
#23 0x2ba402c2beaa in xsltProcessOneNode () from
/usr/lib/libxslt.so.1
#24 0x2ba402c2caea in xsltApplyTemplates () from
/usr/lib/libxslt.so.1
#25 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#26 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#27 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#28 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#29 0x2ba402c2b6be in ?? () from /usr/lib/libxslt.so.1
#30 0x2ba402c2beaa in xsltProcessOneNode () from
/usr/lib/libxslt.so.1
#31 0x2ba402c2caea in xsltApplyTemplates () from
/usr/lib/libxslt.so.1
#32 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#33 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#34 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#35 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
---Type  to continue, or q  to quit---
#36 0x2ba402c2b6be in ?? () from /usr/lib/libxslt.so.1
#37 0x2ba402c2bbca in xsltCallTemplate () from /usr/lib/libxslt.so.1
#38 0x2ba402c2a176 in ?? () from /usr/lib/libxslt.so.1
#39 0

#41086 [Fbk->Opn]: Seg fault and "corrupted double-linked list" with xslt warning

2007-04-15 Thread harvey dot robin at gmail dot com
 ID:   41086
 User updated by:  harvey dot robin at gmail dot com
 Reported By:  harvey dot robin at gmail dot com
-Status:   Feedback
+Status:   Open
 Bug Type: XSLT related
 Operating System: Ubuntu feisty
 PHP Version:  5CVS-2007-04-14 (snap)
 New Comment:

The method given by Christian also works fine to reproduce the crash.


Previous Comments:


[2007-04-15 08:19:01] judas dot iscariote at gmail dot com

shortest possible way to reproduce I can find

http://hell.kissofjudas.net/bug41086.tar.bz2

execute the test.php file.

PHP Warning:  XSLTProcessor::transformToXml(): Invalid type in
/home/cristian/talta/test/test.php on line 6

Warning: XSLTProcessor::transformToXml(): Invalid type in
/home/cristian/talta/test/test.php on line 6
PHP Warning:  XSLTProcessor::transformToXml(): xmlXPathCompiledEval: 3
object left on the stack in /home/cristian/talta/test/test.php on line
6

Warning: XSLTProcessor::transformToXml(): xmlXPathCompiledEval: 3
object left on the stack in /home/cristian/talta/test/test.php on line
6

Program received signal SIGSEGV, Segmentation fault.
[snip`libxml stripped libxml messages]
#85 0x2ad626e0b8ce in php_xsl_apply_stylesheet (id=0xc77238,
intern=0xc79a80, style=0xd66c20, docp=0xc7adf8)
at /home/cristian/php5/ext/xsl/xsltprocessor.c:472
newdocp = (xmlDocPtr) 0x7fff86737a30
doc = (xmlDocPtr) 0xeb12b0
node = (xmlNodePtr) 0xeb12b0
ctxt = (xsltTransformContextPtr) 0xeb8160
object = (php_libxml_node_object *) 0xc7a5a0
params = (char **) 0xc7a920
clone = 0
doXInclude = (zval *) 0xad32a8
member = (zval *) 0xc7ace0
std_hnd = (zend_object_handlers *) 0xacbc00
#86 0x2ad626e0bc66 in zif_xsl_xsltprocessor_transform_to_xml (ht=1,
return_value=0xc79f78, return_value_ptr=0x0,
this_ptr=0xc77238, return_value_used=1) at
/home/cristian/php5/ext/xsl/xsltprocessor.c:583
id = (zval *) 0xc77238
docp = (zval *) 0xc7adf8
newdocp = (xmlDoc *) 0xc79f78
sheetp = (xsltStylesheetPtr) 0xd66c20
ret = 24
doc_txt_ptr = (xmlChar *) 0x7fff86737a30 "8zs\206�\177"
doc_txt_len = 0
intern = (xsl_object *) 0xc79a80
---Type  to continue, or q  to quit---
#87 0x0072c378 in zend_do_fcall_common_helper_SPEC
(execute_data=0x7fff86737a90)
at /home/cristian/php5/Zend/zend_vm_execute.h:200
return_reference = 0 '\0'
opline = (zend_op *) 0xc78eb0
original_return_value = (zval **) 0x7fff867376d0
current_scope = (zend_class_entry *) 0x0
current_this = (zval *) 0x0
return_value_used = 1
should_change_scope = 1 '\001'
ctor_opline = (zend_op *) 0x7fff86737a90
#88 0x0072d245 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER
(execute_data=0x7fff86737a90)
at /home/cristian/php5/Zend/zend_vm_execute.h:322
No locals.
#89 0x0072bdc0 in execute (op_array=0xc77f70) at
/home/cristian/php5/Zend/zend_vm_execute.h:92
execute_data = {opline = 0xc78eb0, function_state =
{function_symbol_table = 0x0, function = 0xc43b30, reserved = {
  0x63006cfe49, 0x82cb80, 0xc780b0, 0x7fff86737b00}}, fbc =
0xc43b30, op_array = 0xc77f70, object = 0xc77238,
  Ts = 0x7fff86737760, CVs = 0x7fff86737730, original_in_execution = 0
'\0', symbol_table = 0xad3428,
  prev_execute_data = 0x0, old_error_reporting = 0x0}
#90 0x007022f4 in zend_execute_scripts (type=8, retval=0x0,
file_count=3) at /home/cristian/php5/Zend/zend.c:1134
files = {{gp_offset = 40, fp_offset = 48, overflow_arg_area =
0x7fff86737ca0, reg_save_area = 0x7fff86737be0}}
i = 1
file_handle = (zend_file_handle *) 0x7fff8673a090
orig_op_array = (zend_op_array *) 0x0
orig_retval_ptr_ptr = (zval **) 0x0
local_retval = (zval *) 0x0
#91 0x0069fd01 in php_execute_script
(primary_file=0x7fff8673a090) at /home/cristian/php5/main/main.c:1790
realfile =
"/home/cristian/talta/test/test.php\000_query_type\000\000�\006\000\000�\177\000\000�\231p\000\000\000\000\000rpl_probe\000\202\000\000\000\000\000�\006\000\000\000\000\000\000
\217s\206\017\000\000\000rpl_parse_enabled\000\000\000\000\000\000\000��\202\000\000\000\000\000�\006\000\000�\177\000\000�\231p\000\000\000\000\000rollback\000�\202\000\000\000\000\000�\006\000\000�\177\000\000�\231p\000\000\000\000\000real_query\000\000\000\000\000\000�\006\000\000�\177\000\000"...
__orig_bailout = (jmp_buf *) 0x7fff86739f40
__bailout = {{__jmpbuf = {47099221150688, -68967799470258375,
0, 140735449113296, 0, 0, -68967799470267079,
---Type  to continue, or q  to quit---
  -69095675644025930}, __mask_was_saved = 0, __saved_mask = {__val
= {0, 0, 47099218988917, 1, 0, 140733193389737,
7379374, 47099240203304, 47099221150688, 140735449107936,
47099219010530,