Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:29953 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28188 invoked by uid 1010); 30 May 2007 14:38:47 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 28172 invoked from network); 30 May 2007 14:38:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 May 2007 14:38:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=colder@php.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=colder@php.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain php.net from 213.239.212.54 cause and error) X-PHP-List-Original-Sender: colder@php.net X-Host-Fingerprint: 213.239.212.54 dns1.omne-serveurs.net Linux 2.4/2.6 Received: from [213.239.212.54] ([213.239.212.54:46909] helo=dns1.omne-serveurs.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/7A-51978-17C8D564 for ; Wed, 30 May 2007 10:38:44 -0400 Received: (qmail 26633 invoked from network); 30 May 2007 14:38:35 -0000 Received: from 80.218.249.160 by dns1 (envelope-from , uid 1004) with qmail-scanner-1.23 (clamdscan: 0.82. spamassassin: 3.0.1. perlscan: 1.32. Clear:RC:1(80.218.249.160):. Processed in 0.083532 secs); 30 May 2007 14:38:35 -0000 Received: from 80-218-249-160.dclient.hispeed.ch (HELO ?10.0.0.1?) (80.218.249.160) by dns1.omne-serveurs.net with (DHE-RSA-AES256-SHA encrypted) SMTP; 30 May 2007 14:38:35 -0000 Message-ID: <465D8C6B.2000809@php.net> Date: Wed, 30 May 2007 16:38:35 +0200 User-Agent: Thunderbird 1.5.0.7 (X11/20060909) MIME-Version: 1.0 To: internals@lists.php.net Content-Type: multipart/mixed; boundary="------------070708080409090503070405" Subject: [patch] Callbacks bug/change request From: colder@php.net (Etienne Kneuss) --------------070708080409090503070405 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi internals, It seems that there is a bug in the way some callbacks are handled. For instance: array('B', 'parent::who'); Here, the classname 'B' will only be used for inheritance checks with the current scope, but the actual resolution will be made using the current scope, and 'parent::who'. According to Marcus, this is wrong, so here is two patches (+ tests) meant for HEAD [1] and the 5_2 branch (>5.2.3) [2]. Thanks for your consideration. Regards 1: http://patches.colder.ch/Zend/callbacks_HEAD.patch?markup 2: http://patches.colder.ch/Zend/callbacks_5_2.patch?markup -- Etienne Kneuss http://www.colder.ch colder@php.net Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal --------------070708080409090503070405 Content-Type: text/plain; name="callbacks_5_2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="callbacks_5_2.patch" Index: ext/standard/tests/general_functions/callbacks_001.phpt =================================================================== RCS file: ext/standard/tests/general_functions/callbacks_001.phpt diff -N ext/standard/tests/general_functions/callbacks_001.phpt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ext/standard/tests/general_functions/callbacks_001.phpt 27 May 2007 21:38:48 -0000 @@ -0,0 +1,55 @@ +--TEST-- +ZE2 Callbacks of static functions +--FILE-- +foo(); +?> +===DONE=== +--EXPECT-- +B +B +A +D +A +A +B +===DONE=== Index: Zend/zend_API.c =================================================================== RCS file: /repository/ZendEngine2/zend_API.c,v retrieving revision 1.296.2.27.2.30 diff -u -r1.296.2.27.2.30 zend_API.c --- Zend/zend_API.c 16 May 2007 18:57:15 -0000 1.296.2.27.2.30 +++ Zend/zend_API.c 27 May 2007 21:38:50 -0000 @@ -2125,6 +2125,8 @@ mlen = Z_STRLEN_P(callable) - clen - 2; lcname = zend_str_tolower_dup(Z_STRVAL_P(callable), clen); /* caution: lcname is not '\0' terminated */ + zend_class_entry *last_scope = EG(scope); + EG(scope) = ce_org; if (clen == sizeof("self") - 1 && memcmp(lcname, "self", sizeof("self") - 1) == 0) { *ce_ptr = EG(scope); } else if (clen == sizeof("parent") - 1 && memcmp(lcname, "parent", sizeof("parent") - 1) == 0 && EG(active_op_array)->scope) { @@ -2132,6 +2134,7 @@ } else if (zend_lookup_class(Z_STRVAL_P(callable), clen, &pce TSRMLS_CC) == SUCCESS) { *ce_ptr = *pce; } + EG(scope) = last_scope; efree(lcname); if (!*ce_ptr) { return 0; Index: Zend/zend_execute_API.c =================================================================== RCS file: /repository/ZendEngine2/zend_execute_API.c,v retrieving revision 1.331.2.20.2.19 diff -u -r1.331.2.20.2.19 zend_execute_API.c --- Zend/zend_execute_API.c 27 Apr 2007 08:12:24 -0000 1.331.2.20.2.19 +++ Zend/zend_execute_API.c 27 May 2007 21:38:53 -0000 @@ -750,7 +750,8 @@ if ((colon = strstr(fname, "::")) != NULL) { int clen = colon - fname; int mlen = fname_len - clen - 2; - zend_class_entry **pce, *ce_child = NULL; + zend_class_entry **pce, *ce_child = NULL, *last_scope = EG(scope); + EG(scope) = calling_scope; if (zend_lookup_class(fname, clen, &pce TSRMLS_CC) == SUCCESS) { ce_child = *pce; } else { @@ -765,6 +766,7 @@ } efree(lcname); } + EG(scope) = last_scope; if (!ce_child) { zend_error(E_ERROR, "Cannot call method %s() or method does not exist", fname); return FAILURE; --------------070708080409090503070405 Content-Type: text/plain; name="callbacks_HEAD.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="callbacks_HEAD.patch" Index: Zend/zend_API.c =================================================================== RCS file: /repository/ZendEngine2/zend_API.c,v retrieving revision 1.433 diff -u -r1.433 zend_API.c --- Zend/zend_API.c 16 May 2007 18:56:38 -0000 1.433 +++ Zend/zend_API.c 27 May 2007 15:31:44 -0000 @@ -2561,7 +2561,11 @@ } } if (colon.v != NULL) { + zend_class_entry *last_scope = EG(scope); + EG(scope) = ce_org; *ce_ptr = zend_u_fetch_class(Z_TYPE_P(callable), Z_UNIVAL_P(callable), clen, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + EG(scope) = last_scope; + if (!*ce_ptr) { return 0; } Index: ext/standard/tests/general_functions/callbacks_001.phpt =================================================================== RCS file: ext/standard/tests/general_functions/callbacks_001.phpt diff -N ext/standard/tests/general_functions/callbacks_001.phpt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ext/standard/tests/general_functions/callbacks_001.phpt 27 May 2007 15:31:44 -0000 @@ -0,0 +1,55 @@ +--TEST-- +ZE2 Callbacks of static functions +--FILE-- +foo(); +?> +===DONE=== +--EXPECT-- +B +B +A +D +A +A +B +===DONE=== --------------070708080409090503070405--