Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7422 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11168 invoked by uid 1010); 30 Jan 2004 14:59:40 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 11072 invoked from network); 30 Jan 2004 14:59:39 -0000 Received: from unknown (HELO asuka.nerv) (24.100.195.79) by pb1.pair.com with SMTP; 30 Jan 2004 14:59:39 -0000 Received: (qmail 31961 invoked from network); 30 Jan 2004 14:59:39 -0000 Received: from rei.nerv (HELO dummy.com) (rei@192.168.1.1) by asuka.nerv with SMTP; 30 Jan 2004 14:59:39 -0000 Reply-To: ilia@prohost.org To: Rasmus Lerdorf , internals@lists.php.net Date: Fri, 30 Jan 2004 09:59:41 -0500 User-Agent: KMail/1.5.94 References: In-Reply-To: Organization: Prohost.org MIME-Version: 1.0 Content-Disposition: inline Content-Type: Multipart/Mixed; boundary="Boundary-00=_dFnGAL3fZENfdJW" Message-ID: <200401300959.41785.ilia@prohost.org> Subject: Re: [PHP-DEV] Warnings in include files suddenly treated as fatal From: ilia@prohost.org (Ilia Alshanetsky) --Boundary-00=_dFnGAL3fZENfdJW Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline It seems like the only way to distinguish between a parse error and a non-existant file for regular include() is by doing a zend_stream_open() upon failure to determine if the file is avaliable. If it is, then we return a parse error and if it does not we continue execution. This does add a small overhead for failed includes, but IMHO if a non-existant files are being included performance is not a big consideration. That said, if there is much opposition to the approach I would be happy to revert the code to the previous state. Ilia P.S. Suggested 'fix' is attached. On January 30, 2004 05:29 am, Rasmus Lerdorf wrote: > Ilia, I think there is a problem with your latest fixes on the 4_3 branch. > Stuff that used to work is now broken. Stuff like this: > > main.php: > > include 'inc1.inc'; > > inc1.inc: > > @include 'inc2.inc'; > > If inc2.inc does not exist we now get an error similar to: > > Warning: main(./lang/serendipity_lang_.inc.php): failed to open stream: No > such file or directory in /var/www/s9y/serendipity_lang.inc.php on line 5 > > Warning: main(): Failed opening './inc2.inc' for > inclusion (include_path='.:/usr/local/lib/php') on line {the include line > #} > > Fatal error: Parse error inside included file. in > /var/www/htdocs/inc1.inc on line {the include line #} > > Remember that it is ok for an include to not find the file. We issue a > warning and move on. It should in no way be treated as a fatal error. > > -Rasmus --Boundary-00=_dFnGAL3fZENfdJW Content-Type: text/plain; charset="iso-8859-1"; name="zeinc.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="zeinc.txt" Index: zend_execute.c =================================================================== RCS file: /repository/ZendEngine2/zend_execute.c,v retrieving revision 1.592 diff -u -3 -p -r1.592 zend_execute.c --- zend_execute.c 30 Jan 2004 02:22:17 -0000 1.592 +++ zend_execute.c 30 Jan 2004 14:56:23 -0000 @@ -3390,7 +3390,13 @@ int zend_include_or_eval_handler(ZEND_OP case ZEND_REQUIRE: new_op_array = compile_filename(EX(opline)->op2.u.constant.value.lval, inc_filename TSRMLS_CC); if (!new_op_array) { - zend_error(E_ERROR, "Parse error inside included file."); + zend_file_handle file_handle; + zend_bool can_open = zend_stream_open(inc_filename->value.str.val, &file_handle TSRMLS_CC); + zend_file_handle_dtor(&file_handle); + + if (can_open != SUCCESS) { + zend_error(E_ERROR, "Parse error inside included file."); + } } break; case ZEND_EVAL: { --Boundary-00=_dFnGAL3fZENfdJW--